Skip to content

Instantly share code, notes, and snippets.

@jeffandersen
Last active October 6, 2015 21:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffandersen/3055596 to your computer and use it in GitHub Desktop.
Save jeffandersen/3055596 to your computer and use it in GitHub Desktop.
Super simple git aliases that are based around prefixing branch names with your Github username
determineBranch() {
GIT_USERNAME=$(git config --global user.user)
if [ -z "$GIT_USERNAME" ]; then
echo "No user found in git config. Set key 'user' to your github username."
BRANCH_NAME=$1
else
if [ -n "$1" ]; then
if [[ $1 == *-n* && -n "$2" ]]; then
BRANCH_NAME=$2
else
BRANCH_NAME="$GIT_USERNAME/$1"
fi
else
BRANCH_NAME=$(git_branch)
fi
fi
echo "$BRANCH_NAME"
}
branch() {
determineBranch "$@"
echo "Creating branch $BRANCH_NAME"
git checkout -b $BRANCH_NAME
git push -u origin $BRANCH_NAME
}
delete() {
determineBranch "$@"
git checkout master
git branch -d $BRANCH_NAME
git push origin ":$BRANCH_NAME"
}
merge() {
determineBranch "$@"
git fetch
git merge --no-ff origin/$BRANCH_NAME
}
pull() {
determineBranch "$@"
git pull --rebase origin $BRANCH_NAME
}
push() {
determineBranch "$@"
git push origin $BRANCH_NAME
}
checkout() {
determineBranch "$@"
git checkout $BRANCH_NAME
}
alias last='git checkout -'
alias fetch='git fetch'
alias stash='git stash'
alias pop='git stash pop'
alias log='git log --oneline --decorate'
alias status='git status'
alias standup="git log --reverse --branches --since=yesterday --author=$(git config --get user.email) --format=format:'%C(cyan) %ad %C(yellow)%h %Creset %s %Cgreen%d' --date=local"
git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'
}
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
PS1="\\[$(tput setaf 7)\\]\\w \$(parse_git_branch)> \\[$(tput sgr0)\\]"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment