Patricio Treviño

Patricio Treviño

Husband . Father . Developer

Rebase a pull request

There is nothing more daunting than rebasing your first pull request. I still remember the day I was asked to do this and, honestly, I can't recall how I pulled it off, but I did... of course this was years ago when there was no Update branch button in Github (which by the way, does a merge commit which I personally dislike). So I'm gonna save you some time and a lot of trouble with this mini guide.

Steps

  1. Clone the repository (if you don't have it already).
    git clone https://github.com/<user>/<repository>
    i.e
    git clone https://github.com/weirdpattern/eslint-plugin-typescript
    view raw 1.sh hosted with ❤ by GitHub
  2. Add the remote repository (if you don't have it already).
    git remote add <remote> https://github.com/<other_user>/<remote_repository>
    i.e.
    git remote add upstream https://github.com/bradzacher/eslint-plugin-typescript
    view raw 2.sh hosted with ❤ by GitHub
  3. Checkout the branch you want to rebase.
    git checkout <branch_to_rebase>
    i.e.
    git checkout camelcase-rule
    view raw 3.sh hosted with ❤ by GitHub
  4. Fetch the latest from the remote branch.
    git fetch <remote> <branch>
    i.e.
    git fetch upstream master
    view raw 4.sh hosted with ❤ by GitHub
  5. Rebase the remote branch onto your current branch.
    git rebase <remote>/<branch>
    i.e.
    git rebase upstream/master
    view raw 5.sh hosted with ❤ by GitHub
  6. Resolve any conflicts (if any)
    git add .
    git rebase --continue
    view raw 6.sh hosted with ❤ by GitHub
  7. Force a push (this is important, otherwise is mess up the entire history).
    git push -f
    view raw 7.sh hosted with ❤ by GitHub

That's it... this wasn't so bad, was it?

Happy Coding!