Skip to content

Instantly share code, notes, and snippets.

@nuweb
Created October 20, 2015 20:28
Show Gist options
  • Save nuweb/8a45890ef7a4beab3764 to your computer and use it in GitHub Desktop.
Save nuweb/8a45890ef7a4beab3764 to your computer and use it in GitHub Desktop.
Git Rebasing and Squash Commits
1. Branch off of develop.
$ git checkout -b feature/myfeature develop
2. Squash commits into one commit
Open github and figure out how many commits to go back
$ git rebase -i head~(number of commits)
- You can remove commits in editor by doing {command K}.
- Save!
3. Checkout develop and make sure it's up to date
$ git checkout develop
$ git pull
4. Checkout feature branch and rebase develop
$ git checkout feature/myfeature
$ git rebase develop
5. Use merge tool, resolve conflicts, and continue rebasing after diff merge
$ git status
$ git mergetool
$ git rebase --continue
5. Force Push feature branch
$ git push -f
6. Checkout develop and merge the feature branch
$ git checkout develop
$ git merge feature/myfeature
7. Push
$ git push
8. Delete the feature branch
$ git branch -D myfeature
Notes: If anything goes wrong abort the rebase, delete and pull the feature branch and start again.
git rebase --abort
git branch -D myfeature
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment