Skip to content

Instantly share code, notes, and snippets.

@jontwo
Forked from justintv/.bashrc
Created November 17, 2017 14:26
Show Gist options
  • Save jontwo/8f1616102d52a61baa7194427df134b9 to your computer and use it in GitHub Desktop.
Save jontwo/8f1616102d52a61baa7194427df134b9 to your computer and use it in GitHub Desktop.
Display git branch in bash prompt
# 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$
@jontwo
Copy link
Author

jontwo commented Nov 17, 2017

This version works for me:
PS1='[\033[0;32m][\033[0m\033[0;32m]\u[\033[0;36m] @ \w[\033[0;32m] ($(git branch 2>/dev/null | grep "^*" | colrm 1 2))\n[\033[0;32m]└─[\033[0m\033[0;32m] $[\033[0m\033[0;32m][\033[0m] '

@jontwo
Copy link
Author

jontwo commented Nov 17, 2017

This is worth adding to .bashrc too:

alias gl="git log --oneline --all --graph --decorate  $*"
alias gs="git status"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment