Git rm – Remove a file from source control without deleting it

The git rm command will allows you to remote a file from git control. The –cached option to git remove allows you to leave it on your hard drive.

Every once in awhile a file gets checked into git that isn’t supposed to be there. Common examples are configuration files, project files generated by your IDE with personal settings and even the occasional object file that someone decided to check in. These files are needed, so often you can’t delete them entirely and the process of copying them somewhere else, removing them from git and then replacing is painful, not to mention prone to error.

By adding the –cached option to the git rm command, you are able to remote the file file from git control while keeping the file in your working tree. They command syntax is:

git rm --cached file

Git will no longer track this file even though it is still on your hard drive.

After running the above command, be sure to add an entry to your .gitignore file so that ‘file’ doesn’t show up in ‘git status’ and that it can’t accidentally be re-added later.


Comment Form




Recent Articles

Where Do I Get Git?

Where do you get git? We have the answer to that for Linux (Ubuntu, Debian, and Red Hat), Windows, and Apple OS as well as over 30 free git tutorials.

What is the deal with the Git Index? What is the Git Index?

The git "index" is where you place files you want committed to the git repository. Learn more about the git index and git commit by selecting this link.

What Every VCS Must do

Version Control System ("VCS") need to be able to provide to its users? GitGuys explains exactly what it needs to include and provides tutorials on Git.

Visualising Branches And Their Commits

We explain and discuss the use of the git show-branch, gitg, gitk and qgit in this Tutorial. Complete with examples.

“Tracking Branches” And “Remote-Tracking Branches”

Both Tracking Branches and Remote Tracking Branches are created on the git client when a git clone command is used.

Related Stories

Leave A Reply

Please enter your comment!
Please enter your name here

Stay on op - Ge the daily news in your inbox