Quantcast
Channel: Computing Tips – Ben Lobaugh Online
Viewing all articles
Browse latest Browse all 31

Quick and easy way to show the current Git branch on your command prompt

$
0
0

If you work with lots of branches in Git it is nice to be able to see at a glance which branch you are on instead of typing git branch each time. Here are 4 quick lines you can add to your bash prompt that will show the current branch.

You will need to edit your user bash config which can be in different locations depending on your operating system.

  • OS X: ~/.profile
  • Linux General: ~/.bash_profile

~ represents the path to your user home directory. For my user, blobaugh, on OS X the path is /Users/home/blobaugh.

Add in the file the following lines:

  1. parse_git_branch() {
  2. git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
  3. }
  4. export PS1="\u@\h \W\[\033[31m\]\$(parse_git_branch)\[\033[00m\] $ "
  5.  

Restart your terminal and change directories to your repository and you should now see the branch in parenthesis at the end of your prompt.

Screen Shot 2014-01-14 at 3.55.32 PM


Viewing all articles
Browse latest Browse all 31

Trending Articles