Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagebash
linenumberstrue
git fetch upstream # First get the latest changes.
git rebase upstream/<branch> # Rebase on top of upstream's branch, could be "master".

... # Fix any conflicts then run git rebase --continue

git push --force-with-lease origin <branch> # Push your changes to your feature branch.
											# A force push is necessary as the history just changed.

As an optional step and desirable if your history contains a series of commits that address the same functional change, you can squash the commits into a single one, this is done with an interactive rebasing.
(For additional information on interactive rebasing, please visit https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History)

Code Block
languagebash
linenumberstrue
git rev-list --count upstream/<branch>..HEAD # Get the number of commits between your branch and upstream's (could be master).
git rebase -i HEAD~N # Where "N" is the number of commits given by the previous command.

... # Your favorite text editor will start and shows the commands for the interactive rebasing.
... # Change the "pick" to "squash" for all the commits you want to squash.
... # For the series of commits to squash, keep the first one with "pick".
... # Once you save and exist your editor will start again to merge all the commit messages.
... # Add a commit message that best describes your change then save and exit.

git push --force-with-lease origin <branch> # Push your changes to your feature branch.
											# A force push is necessary as the history just changed.

Generating a Patch from a Clone

...