Adding Git repo and branch to Tmux status line
Solution 1
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.
Solution 2
This is a lot easier in newer versions of tmux:
set -g status-right '#(cd #{pane_current_path}; git rev-parse --abbrev-ref HEAD)'
Solution 3
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
:
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.
Related videos on Youtube
dotancohen
Updated on September 18, 2022Comments
-
dotancohen over 1 year
I have found a Tmux configuration file that shows how to add the Git branch to the Tmux status line, however It just shows
[[ branch ]]
no matter if I am in a Git repo or not. I am not sure if this requiresgit-completion
, but if so I'm not even sure if it is installed as it is a 'virtual' package in Ubuntu (the leading 'v' means 'virtual'):$ aptitude search git-completion v git-completion $ sudo apt-get install git-completion Reading package lists... Done Building dependency tree Reading state information... Done Note, selecting 'git' instead of 'git-completion' git is already the newest version.
How might I add the branch and also the git repo name for the CWD to the Tmux status line?
Thanks.
-
Speederer about 8 yearsThis doesn't really answer the question, just provides a workaround for
bash
users. -
Jasha almost 3 yearsThis works, but it does not update when I change directory or git branch. It only updates when I use the tmux prefix to update tmux's state.