Tree supports the -I flag.
-I pattern Do not list those files that match the wild-card pattern.
-I patternDo not list those files that match the wild-card pattern.
Tree supports a single pattern which will exclude all files/directories that match it.
Git's ignore files are a bit more complicated:
Exclusion can come from multiple files, $HOME/.config/git/ignore, the output of git config --get core.excludesfile , .gitignore (per directory), ~/.gitignore, and more (see man gitignore).
Another problem is the patterns that tree supports differs from what git does (as noted by @Brad Urani).
But we can get close-ish ...
tree -I "$(grep -hvE '^$|^#' {~/,,$(git rev-parse --show-toplevel)/}.gitignore|sed 's:/$::'|tr \\n '\|')"
Or as a function:
function gtree {
git_ignore_files=("$(git config --get core.excludesfile)" .gitignore ~/.gitignore)
ignore_pattern="$(grep -hvE '^$|^#' "${git_ignore_files[@]}" 2>/dev/null|sed 's:/$::'|tr '\n' '\|')"
if git status &> /dev/null && [[ -n "${ignore_pattern}" ]]; then
tree -I "${ignore_pattern}" "${@}"
else
tree "${@}"
fi
}