Skip to content

Instantly share code, notes, and snippets.

@DarkPanth3r
Last active November 7, 2021 09:36
Show Gist options
  • Save DarkPanth3r/cdd781dc517bbfeb633563791c273c8d to your computer and use it in GitHub Desktop.
Save DarkPanth3r/cdd781dc517bbfeb633563791c273c8d to your computer and use it in GitHub Desktop.
How to show the git branch in Linux terminal

This article will explain how to see the git branch on linux terminal.

  1. Go to ~/.bashrc
  2. Make an copy of the bashrc file before doing the changes(only for security reasons).
  3. Open bashrc with sudo and between lines 59 and 64 wich originaly look like this: image

Should be replaced by:

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
# THE SIX LINES BELOW are the default prompt and the unset (which were in the original .bashrc)
#if [ "$color_prompt" = yes ]; then
#    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
#else
#    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
#fi
#unset color_prompt force_color_prompt

Source info: https://askubuntu.com/questions/730754/how-do-i-show-the-git-branch-with-colours-in-bash-prompt

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