Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude some directories from output of git status without having to modify the working tree (e.g. _not_ modifying .gitignore)

Tags:

git

In my working tree there's a directory with several modified files that I temporarily would like to not see when I do git status. But this should ideally be done without modifying the "state" of my working tree. How could I do this?

I looked at man git-status but couldn't see an option to exclude a specific directory.

Some workarounds:

  • Use git status | grep -v dir-to-exclude, but then I lose the pretty colours.
  • Specify all the other directories and files as arguments to git status, i.e. git status dir-1 dir-2 dir-3 file-1 file-2
  • Use git stash to temporarily store modifications in dir-to-exclude/, but that modifies my state
  • Temporarily add dir-to-exclude/ to .gitignore, but that modifies the state of my working tree and I have remember to revert the change. It also does not work for modified version controlled files.
  • Use some other command than git status, if one exists???

If there's no ready made option for git status, then somehow using grep without losing the pretty colours is perhaps what I should be using.

like image 527
chr Avatar asked Dec 17 '25 19:12

chr


1 Answers

Try this

 git -c color.ui=always status | grep -v <dir-to-exclude>

See Colors in Git section here

Git fully supports colored terminal output, which greatly aids in visually parsing command output quickly and easily. A number of options can help you set the coloring to your preference.

color.ui

Git automatically colors most of its output, but there’s a master switch if you don’t like this behavior.

You can also set it to always to ignore the difference between terminals and pipes.

like image 185
Saurabh P Bhandari Avatar answered Dec 20 '25 14:12

Saurabh P Bhandari



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!