Created
December 6, 2014 13:13
-
-
Save 1ik/25fcfe75f358a0620f13 to your computer and use it in GitHub Desktop.
Git rebasing with other branch
This file contains hidden or 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
1) get the latest code from the remote: | |
git fetch origin | |
2) check out the branch you would like to squash | |
git checkout task/user-add-feature | |
3) make sure your local copy is the same as the remote | |
git pull origin | |
4) make sure you have all the commits from the branch you split off from | |
git log HEAD..origin/feature/user-management | |
5) if you have any outstanding commits: | |
5.1) you need to rebase your branch with the "main" branch | |
git rebase origin/feature/user-management | |
5.2) if there are any conflicts resolve until rebase is successful | |
6) find out where the "main" branch and "this" branch split off (the last common ancestor) | |
git merge-base origin/feature/user-management HEAD | |
7) soft reset your current branch to the point described in 6 above (keeps all changes in the files but loose the commits) | |
git reset [commit id from 6] | |
8) prepare your workspace for one commit to represent all the changes for this branch | |
git add --all | |
9) ensure you have got all files into the stage for commit | |
git status | |
10) make a new commit with all the changes (all your existing commits into one) | |
git commit -m "The message that explains what this branch contains" | |
11) check that your branch now only has a single commit ahead of the "main" branch | |
git log origin/feature/user-management..HEAD | |
12) override the remote branch so that is only contains this single commit | |
git push origin task/user-add-feature -f |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment