Last active
April 30, 2018 15:44
-
-
Save jefflaplante/9e25becf3c627296d8c33f1d60c46e24 to your computer and use it in GitHub Desktop.
Rebase Git Workflow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This script will help you squash commits in your feature branch | |
# and enable you to submit a PR to merge your branch with master. | |
# Ensure you have your feature branch checked out with a clean | |
# working directory before rebasing. | |
# Get the current branch - use this as feature branch to merge. | |
feature_branch=$(git rev-parse --abbrev-ref HEAD) | |
# Get merge base and squash commits | |
merge_base=$(git merge-base $feature_branch master) | |
echo "Squash all but the first commit." | |
echo "Add this to your .vimrc for easy squashing:" | |
echo "map s :2,$s/^pick/squash/<CR>" | |
git rebase -i $merge_base | |
# Force rewrite of commit history on feature branch on upstream | |
git push origin $feature_branch --force | |
# Checkout master and pull to make sure we have the latest | |
git checkout master | |
git pull origin master | |
# Rebase feature branch on master - to make it easy to merge the PR. | |
git checkout $feature_branch | |
git rebase master | |
# Force rewrite of commit history on feature branch on upstream | |
git push origin $feature_branch --force | |
echo "Rebase done. Create a PR to merge to master." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment