Abhinav
Abhinav

Reputation: 38162

Showing current GIT branch permanently in terminal

How do I permanently show the current GIT branch in my terminal. After I follow the steps mentioned in here, I get the results but once I quit and re-launch terminal, changes are gone. Also, I do not see colour combinations as mentioned in here.

Please advise.

PS: I am using MacBook Pro.

Upvotes: 0

Views: 1287

Answers (3)

Gunjan Solanki
Gunjan Solanki

Reputation: 41

In order to show current git branch on ubuntu terminal :

  1. Open the ~/.bashrc file with your favourite editor. (I did with nano : sudo nano ~/.bashrc)

  2. Then add the following script:

     git_branch() {
          git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
        }
     export PS1="[\u@\h \W]\[\033[00;32m\]\$(git_branch)\[\033[00m\]\$ "
  1. Load the bashrc file to reflect the branch using source ~/.bashrc

Upvotes: 0

wederer
wederer

Reputation: 570

If you have not looked at zsh and/or prezto yet, take a look here: http://codurance.com/2015/03/16/installing-zprezto-a-quick-guide/

There are several themes that come with prezto which have what you are looking for and zsh has several neat features as well.

Upvotes: 1

fedorqui
fedorqui

Reputation: 290325

The page says that you have to:

# Load in the git branch prompt script.
source ~/.git-prompt.sh

You do this once, but when you log out that step is lost.

To make it permanent, add that line into either your ~/.bashrc or ~/.bash_profile file that gets loaded when you log in.

In fact, it is stated in the page:

Now modify your your bash profile (it’s at ~/.bash-profile [sic, it has to be bash_profile], in case you’re new to this stuff).

Upvotes: 0

Related Questions