GitHub Pull Request

From Dogtag
Revision as of 23:09, 14 September 2018 by Mharmsen (talk | contribs) (Submitting patches)

Jump to: navigation, search


Github Pull Request is a way to keep the official repo clean by allowing other developers to review your patch before it gets merged into the corresponding branch. It offers a lot of benefits over the gerrithub. See Gerrit vs GitHub Pull Request for entire adv/disadvantages

GitHub - Initial setup

  • Clone the upstream project into a local repository
$ git clone 
  • Create a fork of the project by clicking on the fork button:

Gh pr fork.png

  • Now, you'll have your own copy of Forked repo in the format:<your Github ID>/pki
  • Now add this remote to your cloned repo
$ cd pki
$ git remote add personal<your Github ID>/pki
  • Check whether you see the following output:
$ git remote -v
origin (fetch)
origin (push)
personal (fetch)
personal (push)

Travis - Enabling Travis CI for forked repo

1. Go to and sign in using Github (Top right button)

2. Add the forked repository by clicking the + sign next to My Repositories.

Travis 2.png

3. Select the forked repository.

Travis 4.png

If necessary, click on Sync projects from GitHub or Sync account on the top right of the page to refresh the list of repositories.

GitHub - Verify Travis CI for forked repo

In your forked project, (e. g. -<your Github ID>/pki/settings/installations), go to Settings -> Integration & services, verify that Travis CI appears under Services.

Travis 5.png

Submitting patches from a local dev branch

  • Checkout the branch to which you want to submit patch:
# To submit patches to master:
$ git checkout master
# To submit patches to DOGTAG_10_5_BRANCH:
$ git checkout DOGTAG_10_5_BRANCH
  • Create a new local dev branch (which you'll be submitting as the PR):
$ git checkout -b ticket-<number>
  • Make changes (or cherry-pick changes from other branches) and commit them to your new local dev branch:
$ git commit -a <changes>
  • Push the new local dev branch to your repo
# Note that ticket-<number> is the new local dev branch you created
$ git push personal ticket-<number> 
  • This will trigger a travis CI build. Check to see whether you are ready to submit a PR

GitHub - Creating a Pull Request

  • Submit a pull request from your branch

Gh pr newPR.png

  • Choose the correct to and from branch. You should see the list of commits that will form as patch. You'll see a screen similar to this:

Gh pr correct.png

If there is an error, you'll see something like this:

Gh pr incorrect.png

  • Fill in the Commit Message and Commit Description that will appear in the official repo commit history
  • Click on "Create Pull Request"

Merge and update fork

  • Once your patch goes through and changes are reviewed, your patch is ready to be merged
  • Click on the drop down next to "Merge"

Gh pr merge.png

  • Use the following guideline to keep the official repo commit history CLEAN:
Create Merge Commit = Creates a new commit on top of the last commit in the official branch (Not recommended)
Squash & Merge      = Use when you have lot of insignificant commits (like correcting changes from reviewers). This will Squash all your commits into 1 single commit
Rebase & Merge      = Use when your patch is actually a combination of different patches (every commit is significant). This will copy all the commits on top of the last commit in the branch
  • Once merged, Github will provide you an option to delete your branch. DELETE IT!
  • Now, to keep your fork clean and in-sync with official repo do this in your local:
$ git checkout master           # or the branch you want to sync
$ git pull origin master        # or the branch you want to sync
$ git push personal master      # or the branch you want to sync
$ git branch -D ticket-<number> # Delete the local branch which you deleted from Github