How To Remove File From Git-Git Remove Untracked Files

How To Remove File From Git Repository

In this blog post I will show you how to delete file from git repository

To delete file from git hub repository you must follow three steps.

  • Remove file in local repository (working directory)
  • Commit your changes
  • Push your changes to remote git repository(github)

git rm command

You can see in my git working directory I have some files. Now I will show you how to delete decoding.txt file from in this files.

delete file from git repository

Remove File In Local Repository (Working Directory)

So the first step is remove file from current working directory or local repository, for that we use git rm command.

NOTE: before deleting file check whether you are in correct branch. if you execute below commands it will remove file from that branch. in the following steps iam executing below commands from master branch so file will be deleted from master branch in git hub. so if you want to delete file from some other branch first checkout(switch) to that branch and execute below commands. so in which branch you are executing below commands the file will be removed from that branch only. it will not remove file from other branch or it will not effect other branches.

gir rm

git rm decoding.txt.

remove file from git repository

Commit Your Changes

The next step is commit your changes, for that we use git commit command

git commit -m “removed decoding.txt file”

remove file from git

Push Your Changes To Remote Git Repository(GitHub)

now push your changes to remote git hub (remote repository) by git push command

git push

how to delete file from git repo

it will ask your git or bitbucket username and password enter your credentials . after executing this command your changes will be applied in github.

You can go and check the file decoding.txt in github. it  will be removed from the github branch.

git remove files

you can see in the image there is no decoding.txt file in GitHub that means file is deleted from master branch

we executed above commands in master branch. so the file will be deleted in master branch only.

Leave a Reply

Your email address will not be published. Required fields are marked *