Display your current GIT branch in your prompt
I spotted a customised prompt on someone's computer and remembered that you can control what's displayed in your prompt. This led to an immediate Ah-ha moment that I should display my current working GIT branch there to stop having to keep running git branch to remember which branch I'm working in.
I quickly Googled to see if someone else had the same idea (which they invariably have) and found a solution which I have adjusted to the standard Ubuntu prompt.
Add this to your .bashrc file in your home directory:
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* (.*)/(1)/'
}
PS1="${debian_chroot:+($debian_chroot)}u@h:w$(parse_git_branch)$ "
When done, save the file and run . ~/.bashrc to reload the settings and see your new prompt
Mine is: (outside of a git repository)
andrew@thinkpad:~$
and within a repository
andrew@thinkpad:~/dev/test(master)$
Comments
Have your say