GitHub Pull Request
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 https://github.com/dogtagpki/pki.git
- Create a fork of the project by clicking on the fork button:
- Now, you'll have your own copy of forked repo in the format: https://github.com/<your Github ID>/pki.
- Now add this remote forked repo to your locally cloned repo:
$ cd pki $ git remote add personal https://github.com/<your Github ID>/pki
- Check whether you see the following output:
$ git remote -v origin https://github.com/dogtagpki/pki (fetch) origin https://github.com/dogtagpki/pki (push) personal https://github.com/SilleBille/pki.git (fetch) personal https://github.com/SilleBille/pki.git (push)
Travis - Enabling Travis CI for forked repo
1. Go to https://travis-ci.org/ and sign in using Github (Top right button)
2. Add the forked repository by clicking the + sign next to My Repositories.
3. Select the forked repository.
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 https://github.com/<your Github ID>/pki/settings/installations, or in your forked project, go to Settings -> Integration & services, verify that Travis CI appears under Services.
Local Cloned Repo - 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
- Optionally verify that the commit(s) have been committed to the local dev branch:
# For master: $ git branch master * ticket-<number> # For DOGTAG_10_5_BRANCH: $ git branch DOGTAG_10_5_BRANCH master * ticket-<number> $ git log
- Push the new 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.
- Go to https://travis-ci.org/<your Github ID>/pki to check to see whether you are ready to submit a PR.
GitHub - Creating a Pull Request
- Go to https://github.com/<your Github ID>/pki
- Submit a pull request from your branch
- Go to https://github.com/<your Github ID>/pki/compare (a redirect should occur).
- 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:
If there is an error, you'll see something like this:
- Fill in the Commit Message and Commit Description that will appear in the official repo commit history
- Click on "Create Pull Request"
GitHub - 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"
- 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