[Git] Rebase basic
You've made some commits to a feature branch, but you've also committed a hotfix on master that would make a merge messy. Check out the kennel
branch so you can rebase it on master.
git checkout kennel
OK, you're on the kennel
branch. Our goal is to be able to merge kennel
back into master without conflicts or a merge commit. Rebase the current kennel
branch on master
.
git rebase master
With the rebase complete, kennel
should merge with master
cleanly. Switch branches back to master
git checkout master
We're on master
, and we know the kennel
will merge cleanly. Go ahead and merge in thekennel
branch.
git merge kennel
Your co-worker has pushed changes to the master
branch on the origin
repo. Retrieve it without merging it so we can replay our work on top of it.
git fetch
Now that your local repo knows of the latest changes on origin/master
, move your master
commits after the commits from origin/master
.
git rebase
Your co-worker has pushed before you yet again. Better fetch the changes...
git fetch
Now run another rebase to move your commit after the latest fetched one.
git rebase
Uh, oh! Looks like the rebase is in conflict this time! Edit index.html
to fix the conflicting lines. We want to keep our version with Cats
and Dogs
.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Our Cat-alog</title> </head> <body> <nav> <ul> <<<<<<< HEAD <li><a href="cat.html">Cats</a></li> <li><a href="dog.html">Dogs</a></li> ======= <li><a href="cat.html">Felines</a></li> <li><a href="dog.html">Canines</a></li> >>>>>>> Add dogs. </ul> </nav> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Our Cat-alog</title> </head> <body> <nav> <ul> <li><a href="cat.html">Cats</a></li> <li><a href="dog.html">Dogs</a></li>. </ul> </nav> </body> </html>
Now mark the conflicts in "index.html" as resolved.
git add index.html
Now that all conflicts have been resolved and those files added, continue
the current rebase in process.
git rebase --continue