Show current git branch in tmux status bar

For a while I had my current git branch name showing in my ZSH prompt. Which you can pretty easily do if you use something like oh-my-zsh for example. But it became a bit too cluttering for me after some time. Both the width of the prompt and seeing the branch for each command bother me a bit.

Since I am practically always in a tmux session anyway I wanted to see if I could show the current git branch in the tmux status bar. The following was inspired by an answer on StackExchange.

By adding the following lines to your ~/.tmux.conf file you get the current git branch in the right corner of my tmux status bar.

# ~/.tmux.conf

set -g status-right "#(cd #{pane_current_path}; git rev-parse --abbrev-ref HEAD)"
set -g status-right-length 200

For one project we use very long branch names, generated by bitbucket based on a JIRA issue title… ugg. So I had to increase the length of status-right for the branch name not to be cut off somewhere in the middle. The number 200 is taken somewhat out of the air.

Learn more

A great resource for learning more about tmux are its man pages. You can read them online here or from the command-line using the following command:

$ man tmux

Or take a look at this book:

See Also

6 Non-Programming Books for Programmers