Created
August 17, 2009 00:53
-
Star
(389)
You must be signed in to star a gist -
Fork
(72)
You must be signed in to fork a gist
-
-
Save justintv/168835 to your computer and use it in GitHub Desktop.
Display git branch in bash prompt
This file contains hidden or 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$ |
https://gist.github.com/justintv/168835?permalink_comment_id=3718502#gistcomment-3718502 I've been using this approach on all my servers, looks great, I'll provide an update at some point.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
edit: ended up piecing a few things together and overriding the prompt function with an external script.
Careful, even if a lot of people above are talking ZSH, I'm doing bash things here as the original author of the gist did too
Using this stackoverflow answer and this one as basis and sourcing /usr/share/git/git-prompt.sh (path will be different on other distros) above this function
The path section ended up being:
The whole script I've ended up writing:
This ends up looking like so:

checkmark or cross and status for last command,
then user@hostname:~/path/to/project (branch)/path/in/repo