Skip to content

Instantly share code, notes, and snippets.

@cletusw
Created September 14, 2017 20:35
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 cletusw/b424768da84669175453a30cfaa02e4b to your computer and use it in GitHub Desktop.
Save cletusw/b424768da84669175453a30cfaa02e4b to your computer and use it in GitHub Desktop.
Git aliases for an easier rebase workflow
git config --global alias.sync '!f() { echo "$(tput setaf 4)Syncing this branch with origin master$(tput sgr 0)" && git fetch origin master && git rebase origin/master && echo "$(tput setaf 2)Branch sync successful$(tput sgr 0)"; }; f'
git config --global alias.ship '!f() { BRANCH=$(git symbolic-ref --short HEAD) && MERGE_BASE=$(git merge-base origin/master HEAD) && NUM_COMMITS=$(git rev-list --count $MERGE_BASE..) && git log --oneline --stat $MERGE_BASE.. && read -p "$(tput setaf 4)Are you sure you want to ship $(tput bold)$NUM_COMMITS$(tput sgr 0)$(tput setaf 4) commits to $(tput bold)master$(tput sgr 0)? [Y/n] " response </dev/tty && case $response in [yY][eE][sS]|[yY]|"") echo "$(tput setaf 4)Shipping branch $(tput bold)$BRANCH$(tput sgr 0)" ;; *) echo "$(tput setaf 1)Ship aborted by user$(tput sgr 0)"; return 1 ;; esac && git checkout master && (git merge --ff-only - || (echo "$(tput setaf 1)Could not merge branch into local master\nRun git sync before running this command\nIf this error persists, you have local, un-pushed commits in your master branch\nPush them to origin master or move them into a branch before running this command$(tput sgr 0)"; git checkout -; return 1)) && (git push origin master || (echo "$(tput setaf 1)Could not push branch\nRun git sync before running this command$(tput sgr 0)"; git reset --hard HEAD@{1}; git checkout -; return 1)) && echo "$(tput setaf 2)Branch ship successful$(tput sgr 0)"; }; f'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment