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 do 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 = [email protected] 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
The git branch command lets you create, list, rename, and delete branches. It doesn't let you switch between branches or put a forked history back together again. For this reason, git branch is tightly integrated with the git checkout and git merge commands.
When you create a new branch, all that happens is that a new reference is created pointing to a commit. That's why it's so cheap and fast to create branches in Git.
You typically can use the arrow keys to scroll up or down, and can exit by pressing q.
This can happen if your repo has 0 commits. If you make a commit, your current branch will appear when you do: git branch . Show activity on this post. Show activity on this post.
As mentioned in comments to Mark Adelsberger's answer, this was a default behavior change introduced in Git 2.16.
You can turn paged output for git branch
back off by default with the pager.branch
config setting:
git config --global pager.branch false
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:
-F or --quit-if-one-screen
Causes less to automatically exit if the entire file can be displayed on the first screen.-R or --RAW-CONTROL-CHARS
[...]ANSI "color" escape sequences are output in "raw" form.-X or --no-init
Disables sending the termcap initialization and deinitialization strings to the terminal. This is sometimes desirable if the deinitialization string does something unnecessary, like clearing the screen.
If you get the behavior you describe, you most likely have $LESS
set to something else, and unsetting it (unset LESS
) 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:
[core] pager = less -FRX
If you really dislike the pager thing, you can deactivate it globally or on a per-command basis (see other answers).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With