Adding GIT branch in PS1 on terminal

Submitted by Jochus on Thu, 16/02/2017 - 11:23 | Posted in: Linux


I've updated my PS1 variable to the content below. By doing this change, I'm printing the GIT branch I'm currently working on. As I am working on different projects, it helps me indicating if I'm working on the correct branch for a specific project or not:

Original value:

${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$

New value:
${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]\[\033[01;33m\]$(__git_ps1)\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$

So the part I've added (first block indicates the yellow color, second block executes the __git_ps1 command)

\[\033[01;33m\]$(__git_ps1)

Add new comment

The content of this field is kept private and will not be shown publicly.

Full HTML

  • Lines and paragraphs break automatically.
  • You can caption images (data-caption="Text"), but also videos, blockquotes, and so on.
  • Web page addresses and email addresses turn into links automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <bash>, <cpp>, <css>, <html5>, <java>, <javascript>, <php>, <sql>, <xml>. The supported tag styles are: <foo>, [foo].
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.