When I use the git branch
command to list all branches, I see the output of git branch | less
.
The command git branch
is supposed to show a list of branches, like ls
does for files.
This is the output I get:
How I get the default behaviour of git branch
? What causes the paged output?
I am using ZSH with oh_my_zsh
(nothing for Git in there), and my .gitconfig
looks like this:
[user]
email = myemail@mail.com
name = Dennis Haegler
[push]
default = simple
[merge]
tool = vimdiff
[core]
editor = nvim
excludesfile = /Users/dennish/.gitignore_global
[color]
ui = true
[alias]
br = branch
ci = commit -v
cam = commit -am
co = checkout
df = diff
st = status
sa = stash
mt = mergetool
cp = cherry-pick
pl = pull --rebase
[difftool "sourcetree"]
cmd = opendiff \"$LOCAL\" \"$REMOTE\"
[mergetool "sourcetree"]
cmd = /Applications/SourceTree.app/Contents/Resources/opendiff-w.sh
\"$LOCAL\" \"$REMOTE\" -ancestor \"$BASE\" -merge \"$MERGED\"
trustExitCode = true
For those that want to update their
~/.gitconfig
to fix this, it would look like this:As mentioned above, this was a default behavior change introduced in Git 2.16.
You can turn paged output for
git branch
back off by default with thepager.branch
config setting:Not to argue semantics, but the behavior you're getting is the default. That's why you get it when you don't ask for something different. By default,
branch
(and numerous other git commands) use a pager when sending output to the terminal.You can override this default by using the
--no-pager
optionOr if you redirect the output to a file, git should detect that it isn't writing to a terminal and so should not use a pager anyway. (On the other hand, that suggests a scripting use case, in which case you should consider using a plumbing command like
git for-each-ref
in preference togit branch
.)https://git-scm.com/book/en/v2/Git-Internals-Environment-Variables
To solve your issue, you could unset PAGER and GIT_PAGER in your shell.
As other answers pointed out, git defaults to piping itself into a pager (
less
by default) for most commands.An important point, though, is that When the LESS environment variable is unset, Git sets it to FRX, and the consequence is that the user-visible behavior is the same as if the pager was not used when the command's output is short (i.e. if you have only few branches). See man less:
If you get the behavior you describe, you most likely have
$LESS
set to something else, and unsetting it would get rid of the issue while keeping the "pager" behavior for long output. Alternatively, you can activate the behavior for while keeping$LESS
as-is by adding this to your.gitconfig
file:If you really dislike the pager thing, you can deactivate it globally or on a per-command basis (see other answers).