21

I love using tree to list directories, and I have a git repository with all my dotfiles. For me to be able to see them I need to do tree -a, but that will also list the contents inside the .git directory, which most people (myself included) never dare touching.

How would I get tree -a to exclude only the .git directory?

4 Answers 4

32

You need to use the -I flag to exclude a pattern:

tree -a -I '.git'

Hope it helps.

1
  • 2
    For this particular use you can shorten it to tree -aI .git Mar 11, 2021 at 19:09
3

I wrote a node based clone of tree called tree-fiddy that honors gitignore settings. It's pretty alpha right now, but it's working fine on my machines.

2

I was in the need to exclude .git as well as .vendor and didn't know how to specify multiple directories.

This works:

tree -a -I '.git|.vendor'
1
  • 1
    Very interesting, because the intuitive tree -a -I .git -I .vendor is only taking the last one into account.
    – Demi-Lune
    Apr 25 at 15:59
0

Tree has added a --gitignore flag as of tree Version 2.0.0 (12/21/2021). This should do what you need.

If you have a version of tree older than this and you have ripgrep installed you could create an alias like this to achieve something similar.

alias itree='rg --files | tree --fromfile'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy