Git (Version Control) - git rm (remove) command

If you are not familiar with Git, check out our getting started article. These examples are based on Linux.

Let's say you have a file that has been committed in Git, and you want to remove the file. Before removing the file, use the git status command to ensure the file does not have any outstanding modifications that need to be committed.

git status foo.txt

# On branch master
nothing to commit (working directory clean)

 

In this example, foo.txt will be removed from Git.

git rm foo.txt
. . .
rm 'foo.txt'

 

The git status command should now show that the change to delete the file is ready to be commited.

git status foo.txt

# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       deleted:    preIHSInstall.sh
#

 

Use the git commit command to commit the change to remove the file from Git.

git commit -m "removing from Git" foo.txt
. . .
 1 files changed, 0 insertions(+), 459 deletions(-)
 delete mode 100755 foo.txt

 

The git status command should now return the following.

git status foo.txt

# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
nothing to commit (working directory clean)

 

Use the git push command to push the change made in your local Git branch, which by default is named master, to the origin Git repository. Origin is the remote Git repository the files were cloned from.

git push origin master

 

The git status command should now return the following.

git status foo.txt

# On branch master
nothing to commit (working directory clean)


Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.





Please enter 94419 in the box below so that we can be sure you are a human.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |