Stage All but One File in Git

- 1 minute read

Sometimes, we need to stage everything in our workspace to a Git commit, except one particular file.

To stage everything except a file called foo.txt, run the following two commands in your terminal:

git add -u
git reset foo.txt

Link to this section Staging all but one folder

A similar approach also works with folders.

Here’s how we could stage everything except a folder called foo:

git add -u
git reset -- foo/*

Notice how we insert the “--” argument and append “/*” to the folder name.

This lets Git know that we’ve provided a path that leads somewhere, and that we want to exclude everything within the folder.

Link to this section Conclusion

I wanted to keep this post short and sweet, and I hope you found it useful!

This is the first of countless handy Git snippets that I look forward to sharing on this blog.