Tree supports the -I flag.
-I pattern Do not list those files that match the wild-card pattern.
For example,
tree -I "$( tr '\n' '\|' < $( git config --get core.excludesfile ) )" /foo
For convenience you could put this into a function:
function gtree {
git_ignore_file=$( git config --get core.excludesfile )
if [[ -f ${git_ignore_file} ]] ; then
tree -I"$( tr '\n' '\|' < "${git_ignore_file}" )" "${@}"
else
tree "${@}"
fi
}
git config --get core.excludesfile will return one file in the following precedence: local (repo/.git/config) > global (~/.gitconfig) > system (default?).
if you want to exclude them all then you can use the --get-all flag instead of --get. eg:
tree -I "$( cat $( git config --get-all core.excludesfile ) 2>/dev/null | tr '\n' '\|' ) )" /bar