Adding Git repo and branch to Tmux status line

This is a lot easier in newer versions of tmux:

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

I developed a Bash script for doing that: tmux-git.

tmux-git shows the Git branch of the current working directory, and also checks for uncommited and stashed changes.


I developer a platform and shell-independent solution to show Git working tree information into Git status bar: gitmux.
Here's the screencast on the project pageREADME:

gitmux screencast

As well as showing the branch and remote, it shows additional information about the status of the Git working tree :

  • number of commits ahead / behind upstream branch, branch divergence
  • number of changed files, staged, modified, conflicts and *stashes** elements
  • colors

How it works

By adding set -g status-right '#(gitmux #{pane_current_path})' to your .tmux.conf, gitmux gets called each the working directory updates or a command is entered in a terminal, gitmux prints a tmux format string of git status, that gets shown in tmux status bar. Or, nothing gets printed in case the working directory is not managed by Git.