GitHub Pull Request

From Dogtag
Revision as of 00:40, 15 September 2018 by Mharmsen (talk | contribs) (Travis - Enabling Travis CI for forked repo)

Jump to: navigation, search


Github Pull Request is a way to keep the official repo clean by allowing other developers to review your patch(es) 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 of a remote forked repo

  • Create a fork of the upstream project by clicking on the fork button:

Gh pr fork.png

  • Now, you'll have your own copy of a remote forked repo in the format:<your Github ID>/pki.

Local Repo - Initial setup

  • Clone the upstream project into a local repository:
$ git clone 
  • Add the remote forked repo to your local 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 the remote forked repo

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

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

Travis 2.png

3. Select the remote 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

  • Go to<your Github ID>/pki/settings/installations, or in your remote forked project, go to Settings -> Integration & services, verify that Travis CI appears under Services.

Travis 5.png

Local Repo - Submitting patches from a local dev branch

  • Within your local repo, checkout the branch to which you want to submit one or more patches:
# 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 local dev branch:
$ git commit -a
  • Optionally verify that the commit(s) have been committed to the local dev branch:
 # For master:
 $ git branch
 * ticket-<number>
 # For DOGTAG_10_5_BRANCH:
 $ git branch
 * ticket-<number>
 $ git log
  • Push the local dev branch to your remote forked 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.

Travis - Verify results of Travis CI build

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 a 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 eventually appear in the official upstream repo commit history.
  • Click on "Create Pull Request".

GitHub - Merge and update fork

  • Once your patches go through and changes are reviewed, your patches are 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 repository:
$ 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