19 November 2015

Good tutorial: https://www.atlassian.com/git/tutorials/rewriting-history/git-rebase Good explanation: http://stackoverflow.com/a/15144275/4191133

Before rebasing, to stay up-to-date with remote:

git fetch origin
git checkout master
git merge --ff origin/master

Before:

                 A1 -> A2 -> [A]
                /
1 -> 2 -> 3 -> 4  -> 5 -> 6 -> 7 -> 8[B]
                                    |
                                    master, HEAD

git checkout A
git rebase master
git push -f origin/A

After:

                                                    HEAD
                                                    |
                                      A1' -> A2' -> [A]
                                     /
1 -> 2 -> 3 -> 4  -> 5 -> 6 -> 7 -> 8[B]
                                    |
                                    master

To fast-forward merge:

git checkout B
git merge A

Finally:

1 -> 2 -> 3 -> 4  -> 5 -> 6 -> 7 -> 8[B] -> A1' -> A2' -> [A]
                                                            |
                                                            master, HEAD

Option: rebase to a certain commit, not HEAD

git rebase 6
                            A1'' -> A2'' -> [A]
                           /
1 -> 2 -> 3 -> 4  -> 5 -> 6 -> 7 -> 8[B]