This interesting bash function will get the git branch of the current working directory and then print it in the shell prompt. This could be very useful for a programmer.
git_branch() { git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/' } PS1='┌──[\u@\h]─[\w]\n└──╼ $(git_branch) ╼ \$ ' |
This looks just like a normal shell prompt.
┌──[jason@jason-desktop]─[~] └──╼ ╼ $ cd Documents/xray-16/ |
But when I cd into a directory containing code I got from Github, it shows that it is using a certain Git branch.
┌──[jason@jason-desktop]─[~/Documents/xray-16] └──╼ (xd_dev) ╼ $ |
This indeed would be very useful for someone who uses Git on a regular basis, this would inform you which branch you are pushing to and hopefully avoid embarrassing mistakes.