Git: Deleting files? Use 'git rm' not just 'rm'
Simon Justesen
Posted on April 21, 2022
I use Git a lot in my everyday life. I love it, for the most part, but it can scare the hell out of me too. Especially around the time, where you want to clean up your repository.
One day, you might rearrange some files, delete a few directories. When you're done, you think to yourself: "Ahh, this is nice, let me commit the changes to my remote repo".
Moments, and a lot of whining later... Your remote repository is a mess of old and new files.
What happened?
You did tell Git to move or remove the files, but you didn't tell it to update its internal index - issuing rm <yourfile>
makes your local repository (origin) nice and tidy, but deleting with rm
does not inform Git that the change needs to happen in your remote repository as well.
Therefore, make it a habit to use git rm
when working inside your local repo, if you want your changes to be reflected remotely.
More: git-rm docs
Posted on April 21, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
November 29, 2024