Does git rm delete the file?

Does git rm delete the file?

tldr; Yes. Yes it does. (use git restore --staged <filename> to un-delete if you made that mistake*)

Does git rm <file/path name> remove the file? How to find out yourself: See man git rm or read on.

Sometimes you find git is tracking files (e.g. binary files like images) which you shouldn't be tracking. Git is for tracking text not blobs like images/bins.

Whilst you can't remove them easily - you can tell git to stop tracking them with the git rm --cached option.

How to tell git to stop tracking previously tracked files

If you just want to stop git from tracking some files or a directory, then use:
git rm --cached <filename> this will stop git from tracking the file and "remove it from the index" without removing the file.

You probably then want to add the file(s)/path to your  .gitignore file to prevent them from being tracked.

*There's no such thing as 'deleting' a commit in git

Sometimes you mistakenly commit files to the git repo which you don't want to track. There's no easy way back from this if you've pushed (and that's the whole point- git works very hard to ensure once committed you can always get the exact file tree back. Shockingly, not all version control systems give you that guarantee (see Linus's biased tech talk on the matter).

But I really do want to remove large files from git, how to I do that?

Yes. You have two options the built-into-git feature git filter-branch or BFG Repo-Cleaner.

Are you trying to remove password committed by mistake? Don't bother. Change the password. The cat is out the bag.

I want to learn more

Consider buying "Oh shit, git!" by Julia Evans and listening to Linus's tech talk explaining his design for git.

Oh shit, git!
If you find git confusing, don’t worry! You’re not alone.People who’ve been using it every day for years still make mistakes and aren’t sure how to fix them. A lot of git commands are confusingly named (why do you create new branches with git checkout?) and there are 20 million different ways to do …
Collect recurring payments with Subscribie - Try Now