[git] git checkout all the files

How can I get rid of all the changes in all the files of my repository?

Say I am in a branch and I did some changes. git status returns a set of files in the "Changes not staged for commit" and I notice I would like to get rid of all of these changes in all the files. How can I do this with a single command?

I know I can do the following to checkout just one file:

git checkout -- <file>

I noticed that git checkout -- alone returns the list of all uncommited files. However, I cannot find a way to checkout all of them, something like git checkout --all.

I checked man git checkout and could not find anything. Also I saw Git: Checkout all files except one and tried git checkout . and did not work either.

Would I have to do it programmatically, by looping through the git checkout -- output?

This question is related to git git-checkout

The answer is


If you want to checkout all the files 'anywhere'

git checkout -- $(git rev-parse --show-toplevel)

Other way which I found useful is:

git checkout <wildcard> 

Example:

git checkout *.html

More generally:

git checkout <branch> <filename/wildcard>

  • If you are in base directory location of your tracked files then git checkout . will works otherwise it won't work