Search code examples
gitbashgit-shell

Automatic display of git status in Linux bash


I started working with git in a Windows system. I used the Git Shell that comes with Git Desktop. This commandline tool always displays the branch you are currently in and a short, colored form of git status (# of untracked files, # of changed files, # of deleted files). I found this really convenient.

Now I changed my system completely to Linux and I did not find anything similar. Is there a way to teach the Linux bash displaying the branch and status just like the Windows Git Shell does? I am currently working with the Xubuntu (16.04) Terminal.


Solution

  • According to the GIT-SCM book, and assuming you are using bash, you can use the git-prompt.sh script provided by either git or some other package manager in your distro.

    . ~/git-prompt.sh
    export GIT_PS1_SHOWDIRTYSTATE=1
    export PS1='\w$(__git_ps1 " (%s)")\$ '