Skip to content

Instantly share code, notes, and snippets.

@ikwyl6
Last active January 29, 2022 22:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ikwyl6/6ca8c1572614733118bbd60dbcd77404 to your computer and use it in GitHub Desktop.
Save ikwyl6/6ca8c1572614733118bbd60dbcd77404 to your computer and use it in GitHub Desktop.
'git status' alias function that colors the output if 'branch is ahead' or 'branch is behind' upstream repo
# created by ikwyl6@protonmail.com
# alias function for 'git status' - colors the 'branch is ahead' or 'branch is behind'
# Add to your .bashrc and then do '$ source ~/.bashrc'
function gs() {
# Do I have any stashes I didn't know about?
git stash list | sed -E -e $'s/stash@\{[0-9]+\}/\e[0;31m&\e[0m/'
if [[ -z "$1" ]]; then
branch="$(git rev-parse --abbrev-ref --symbolic-full-name @{u})"
else branch="$1"
fi
# alias gs - colorize part where local repo is behind or ahead of remote HEAD
git -c color.ui=always status | sed -E -e $'s/branch\ is\ ahead|behind/\e[31m&\e[0m/' -e $'s/branch\ is\ up\ to\ date/\e[0;32m&\e[0m/'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment