Created
August 17, 2009 00:53
-
-
Save justintv/168835 to your computer and use it in GitHub Desktop.
Display git branch in bash prompt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# If you work with git, you've probably had that nagging sensation of not knowing what branch you are on. Worry no longer! | |
export PS1="\\w:\$(git branch 2>/dev/null | grep '^*' | colrm 1 2)\$ " | |
# This will change your prompt to display not only your working directory but also your current git branch, if you have one. Pretty nifty! | |
# ~/code/web:beta_directory$ git checkout master | |
# Switched to branch "master" | |
# ~/code/web:master$ git checkout beta_directory | |
# Switched to branch "beta_directory" | |
# ~/code/web:beta_directory$ |
PS1="\[\e[0;1;34m\]\W \[\e[0;1;33m\]\$(git branch 2>/dev/null | grep '^*' | colrm 1 2)\[\e[0;7;0;37m\]$ "
Try this, for minimal text on terminal, with present working directory in blue and branch in yellow color
[...]
git branch 2>/dev/null | grep '^*' | colrm 1 2
[...]
Or with a newer Git:
git branch --show-current 2>/dev/null
It's not shorter, but easier to understand ;-)
git branch --show-current 2>/dev/null
Is not working with newer git
This has been supported since at least Git 2.28.0, but let us not spend any more time on this. Your solution works for all versions :-)
PS1='[\033[0;32m][\033[0m\033[0;32m]\u[\033[0;36m] @ [\033[0;36m]\h \w[\033[0;32m]$(__git_ps1)\n[\033[0;32m]└─[\033[0m\033[0;32m] $[\033[0m\033[0;32m] ▶[\033[0m] '
Excellent! Thanks!
Great collection!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What is this for?