Skip to content

Instantly share code, notes, and snippets.

@ananth-iyer
Last active July 17, 2019 12:09
Show Gist options
  • Save ananth-iyer/8d7a2ba2b12c2c7529c9e129438b3828 to your computer and use it in GitHub Desktop.
Save ananth-iyer/8d7a2ba2b12c2c7529c9e129438b3828 to your computer and use it in GitHub Desktop.
Show current branch name on Linux Ubuntu terminal without git branch command

**Open up your terminal/SSH and edit below file:

** nano ~/.bashrc

Use sudo command to edit file if you logged in with non-sudo user

Save the below lines at the end of .bashrc file

parse_git_branch() {
     git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
if [ "$color_prompt" = yes ]; then
 PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[01;31m\] $(parse_git_branch)\[\033[00m\]\$ '
else
 PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w$(parse_git_branch)\$ '
fi

Restart your terminal/SSH and browser to project root directoy then you can see the branch name directly

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment