How to unstage files in git

Its not unusual to do git add and real­ize that you for­got to add a file pat­tern into your .git­ig­nore due to which some unnec­es­sary files got added into your stage area. There are a cou­ple of ways to do that.

git stash
git stash pop

Now you have a com­pletely clean stage and you can add stuff again. This is per­haps the sim­plest way to achive this.

If its just a file or two that are both­eri­ing 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 effec­tively replace the file in your stage with its ver­sion in the HEAD all still retain­ing it in your work­ing directory.

How­ever, if you just started out fresh and you for­got to add a .git­ig­nore and acci­den­tally added a bunch of wrong files, the most has­sle free way is to delete your .git folder and start all over.


Ryan Sukale

Ryan is a UX engineer living in San Francisco, California.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *