Skip to content

Instantly share code, notes, and snippets.

@justin808
Last active November 7, 2018 20:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save justin808/81c8073ef09c83c113af to your computer and use it in GitHub Desktop.
Save justin808/81c8073ef09c83c113af to your computer and use it in GitHub Desktop.
zsh with git flow
# depends on justin808 gist named utility.zsh
# https://gist.github.com/justin808/bdef67f37c2cbdba898a
# See forum discussion: http://forum.railsonmaui.com/t/zsh-with-git-flow/135
#### GIT ####
# http://superuser.com/questions/458906/zsh-tab-completion-of-git-commands-is-very-slow-how-can-i-turn-it-off
# fix slow completion on files
# __git_files () {
# _wanted files expl 'local files' _files
# }
# http://notes.envato.com/developers/rebasing-merge-commits-in-git/
# https://gist.github.com/590895
function git_current_branch() {
git symbolic-ref HEAD 2> /dev/null | sed -e 's/refs\/heads\///'
}
alias gpthis='git push origin HEAD:$(git_current_branch) && git branch -u origin/$(git_current_branch) $(git_current_branch) && echo "pushed current branch and set upstream to origin"'
alias s='git status --short'
alias gh='git log --name-status -n'
alias gm='git merge --no-ff'
alias gl='git log'
alias gs='git stash'
alias grhard='git reset --hard'
alias grsoft='git reset --soft'
git-branch-current() {
printf "%s\n" $(git branch 2> /dev/null | grep -e ^* | tr -d "\* ")
}
git-log-last-pushed-hash() {
local currentBranch=$(git-branch-current);
git log --format="%h" -n 1 origin/${currentBranch}
}
git-rebase-unpushed() {
git rebase --interactive $(git-log-last-pushed-hash)
}
gitk_everything() {
gitk --all --date-order $(git log -g --pretty=%H)
}
gitFlowNameForCurrentBranch() {
# next line using sed is greedy
# git_current_branch | sed -e 's/.*\///'
# This is the non-greedy match
git_current_branch | perl -pe "s|.*?/||"
}
alias gfn=gitFlowNameForCurrentBranch
gup_develop() {
current_branch="$(git_current_branch)"
echo current_branch is $current_branch
gco develop && gup && gco "$current_branch"
}
gup_master() {
current_branch="$(git_current_branch)"
echo current_branch is $current_branch
gco master && gup && gco "$current_branch"
}
gup_develop_master() {
gup_develop && gup_master
}
gffs() {
feature=`sanitize $1`
gup_develop_master && echoRun "git flow feature start -F --showcommands $feature"
}
gffp() {
feature=`sanitize $1`
gup_develop_master && echoRun "git flow feature publish --showcommands $feature"
}
gfff() {
gup_develop_master && echoRun "git flow feature finish -F --showcommands $(gitFlowNameForCurrentBranch)" &&
echo "Confirm merge and then push develop" || echo "Examine error messages!"
}
gfrs() {
release=`sanitize $1`
gup_develop_master && echoRun "git flow release start -F --showcommands $release"
}
gfrp() {
release=`sanitize $1`
gup_develop_master && echoRun "git flow release publish -F --showcommands $release"
}
# Changed to
# 1. Be sure to sync up remotes and pull --rebase
# 2. Not push
gfrf() {
gup_develop_master && echoRun "git flow release finish -Fn --showcommands $(gitFlowNameForCurrentBranch)" &&
echo "Confirm merge and then push master" || echo "Examine error messages!"
}
gfhs() {
release=`sanitize $1`
gup_develop_master && echoRun "git flow hotfix start -F --showcommands $release"
}
gfhp() {
release=`sanitize $1`
gup_develop_master && echoRun "git flow hotfix publish --showcommands $release"
}
# Changed to
# 1. Be sure to sync up remotes and pull --rebase
# 2. Not push
gfhf() {
gup_develop_master && echoRun "git flow hotfix finish -Fn --showcommands $(gitFlowNameForCurrentBranch)" &&
echo "Confirm merge and then push master and develop" || echo "Examine error messages!"
}
alias git-diff-master-develop='git log --left-right --graph --cherry-pick master..develop'
alias git-cleanup-merged-branches='git branch --merged develop | grep -v develop | xargs git branch -d'
alias git-cleanup-origin='git remote prune origin'
alias git-cleanup-octopress-merged-branches='git branch --merged source | grep -v source | grep -v master | xargs git branch -d'
git-list-remote-branches-to-remove() {
git branch -r --merged | grep 'origin/' | grep -v "origin/master$" | grep -v "origin/develop$" | sed 's/\s*origin\///'
}
git-list-remote-branches-to-remove-do-it() {
git-list-remote-branches-to-remove | xargs -n 1 git push --delete origin
}
@justin808
Copy link
Author

Updated to use --showcommands option so that one can see what git-flow is doing.

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