Rebasing Guide - acolorbright/handbook GitHub Wiki

Standard rebasing flow

In the terminal, navigate to your project directory. Then execute the following, replacing [your-branch] with the actual name of your branch:

git checkout master
git pull origin master
git checkout [your-branch]
git rebase master
git push origin [your-branch] --force-with-lease

Autosquash rebasing flow

This is the technique to use when you want to edit a commit that isn't the previous commit (in which case you could still use git commit --amend).

You need to use a different technique when making the commit before you can do the rebase.

  1. Make your changes and stage as usual.
  2. Get the hash of the commit you want to edit. (You can use git log for this.)
  3. Do git commit --fixup [hash-of-commit-to-edit]

Now we can start the rebasing.

git checkout master
git pull origin master
git checkout [your-branch]
git rebase -i --autosquash master

Here Git will go into interactive mode (this is the -i flag) and will show you a list of commits. You can edit this list to do all sorts of things like drop certain commits, edit commit messages, and so on. If you're not doing any of that and only want to proceed with your fixup commit, you don't need to edit this list at all. The --autosquash option has already ensured that your fixup commit is in the right order, directly after the commit you want to edit. All you have to do here is to exit the editor to run the rebase.

Finally: git push origin your-branch --force-with-lease

Conflicts with package-lock.json

Merge conflicts with package-lock.json can interrupt the rebasing flow and force you to resolve the conflicts before continuing the rebase. npm CLI engineer Kat Marchán has written a handy tool called npm-merge-driver that can resolve these conflicts automatically. Install locally to your project with npx npm-merge-driver install.


Reference: https://dev.to/maxwell_dev/the-git-rebase-introduction-i-wish-id-had