Skip to content

Instantly share code, notes, and snippets.

@burfo
Last active January 15, 2017 03:17
Show Gist options
  • Save burfo/f531d0ba8f0ac375c79b97b01069810d to your computer and use it in GitHub Desktop.
Save burfo/f531d0ba8f0ac375c79b97b01069810d to your computer and use it in GitHub Desktop.
How to rebase for a pull request

How to rebase for a pull request

  • Add a remote which points to the source which is upstream of the github fork.
>git remote add upstream https://github.com/thekroko/uthgard-herald
  • Update all remote references to their latest revisions
>git remote update
    Fetching origin
    Fetching upstream
    From https://github.com/thekroko/uthgard-herald
     * [new branch]      master     -> upstream/master
  • Switch to your local working branch (replace branch name as appropriate).
>git checkout new-feature/guild-profile
    Switched to a new branch 'new-feature/guild-profile'
  • Make sure there are no local changes. If there are, clean it up by reverting/deleting/etc.
>git status
    On branch new-feature/guild-profile
    Your branch is up-to-date with 'donutttt/new-feature/guild-profile'.
    nothing to commit, working tree clean
  • Rebase against the destination of your pull request (i.e. upstream's master branch). Replace upstream with the name of your remote if it's different.
>git rebase upstream/master
    First, rewinding head to replay your work on top of it...
    Applying: (breaking) rounded out guild model, began function to generate guild data
    Applying: implemented guild data generator, allowed guild profile service to access this data
    Applying: added guild profile service error handling
    Applying: guild component now correctly loads from fake guild data
    Using index info to reconstruct a base tree...
    A       herald/.gitignore
    .git/rebase-apply/patch:178: trailing whitespace.
            if (err) console.log(err);
    warning: 1 line adds whitespace errors.
    Falling back to patching base and 3-way merge...
    Removing herald/src/data/guild-data.json
    Auto-merging .gitignore
    Applying: trying to remove data files
    Using index info to reconstruct a base tree...
    A       herald/.gitignore
    Falling back to patching base and 3-way merge...
    Auto-merging .gitignore
    Applying: attempting to remove data json files
    Applying: trying to resolve merge conflicts
  • If there were conflicts, they would've been called out as an error during the rebase.
  • In my sample output above, there were no conflicts. However, you can see that it has merged herald/.gitignore into .gitignore so you should definitely check this file for accuracy.

  • At this point, you're ready to test your code locally, fix any problems caused by the merge, and then push changes up to your github branch which will update the pull request.
  • When you push, the push will probably be rejected due to a tree change. This is expected, because you rebased which changed the tree. Should that happen, you'll need to force the push (--force). Note that forcing may not be safe if others are working on the branch that you're forcing into (but nobody else should be working in your own github fork branch).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment