• 0

How to unstage files in git

Its not unusual to do git add and realize that you forgot to add a file pattern into your .gitignore due to which some unnecessary files got added into your stage area. There are a couple of ways to do that.

git stash
git stash pop

Now you have a completely clean stage and you can add stuff again. This is perhaps the simplest way to achive this.

If its just a file or two that are botheriing you, and you dont want to mess with the other files that are already there in the stage, you can do this

git reset filename

This will effectively replace the file in your stage with its version in the HEAD all still retaining it in your working directory.

However, if you just started out fresh and you forgot to add a .gitignore and accidentally added a bunch of wrong files, the most hassle free way is to delete your .git folder and start all over.