Skip to content

Instantly share code, notes, and snippets.

@dougbacelar
Last active November 22, 2019 13:40
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 dougbacelar/0802a1a96f9ccae67afb55b5c83ffcc8 to your computer and use it in GitHub Desktop.
Save dougbacelar/0802a1a96f9ccae67afb55b5c83ffcc8 to your computer and use it in GitHub Desktop.
.bashrc file to add the git branch to the command line and git command aliases
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
##### DISPLAY GIT BRANCH NAME WITH COLORS
Cyan="\[\033[0;36m\]" # Cyan
Green="\[\033[0;32m\]" # Green
White="\[\033[0;37m\]" # White
clear # removes the last logged in message
find_git_branch() {
# Based on: http://stackoverflow.com/a/13003854/170413
local branch
if branch=$(git rev-parse --abbrev-ref HEAD 2> /dev/null); then
if [[ "$branch" == "HEAD" ]]; then
branch='detached*'
fi
git_branch="($branch)"
else
git_branch=""
fi
echo $git_branch
}
export PS1="$Green \w $Cyan\$(find_git_branch)$White $ "
#export PS1="\$Green\w \$(find_git_branch)\$Cyan $ "
#####
##### GIT ALIASES
alias newbranch='function _newBranch(){ [ -z "$1" ] && return 1; echo "git checkout -b $1"; git checkout -b $1; echo "git push -u origin $1"; git push -u origin $1; };_newBranch'
alias deletebranch='function _deletebranch(){ [ -z "$1" ] && return 1; echo "git branch -D $1"; git branch -D $1; echo "git push origin -d $1"; git push origin -d $1; };_deletebranch'
alias gs='git status'
alias gp='git push'
alias gd='git diff'
#####
@dougbacelar
Copy link
Author

dougbacelar commented Jan 7, 2019

save these files on the ~/ directory

image

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