Show Git Branch in Command Prompt (Ubuntu)

January 27, 2019
Using git-prompt.sh

Download git-prompt.sh

cd ~
wget https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh -O .git-prompt.sh

Edit .bashrc

nano ~/.bashrc

Add the following at the end of the file

source ~/.git-prompt.sh
PS1='[\u@\h:\w$(__git_ps1 " (%s)")]\$ '

NOTE: You can customize the bash prompt/PS1.

Start a new command prompt or run

source .bashrc

NOTE: You might want to look into bash-git-prompt for a more fancy bash prompt for git.

This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.