Github – Submitting a Pull Request

Overview

Submitting a Github Pull Request

A step by step guide on the pull request cycle. Submitting a pull request is part of a larger process in which external members can make modifications to the existing code base.

Forking

Fork target repository

Cloning involves making a copy of a git repository onto a local machine. In contrast, a fork is a cloning of one git repository to another repository.

Make necessary modifications to the codebase. After this is complete, the next step is to submit a pull request. While submitting a pull request, a message is required indicating any helpful notes describing the task.

Send a pull request, which is simply a request for changes. First check the Comments and Files Changed tab to verify final changes.

Cloning your Fork to local machine
Run the following command to clone the forked repo to your local machine.

# Clone your fork to your local machine
git clone git@github.com:USERNAME/FORKED-PROJECT.git

Keeping your fork up to date
Keep your fork up to date by tracking the original “upstream”, to do this you’ll need to add a remote.

# Add ‘upstream’ repo to list of remotes
git remote add upstream https://github.com/UPSTREAM-USER/ORIGINAL-PROJECT.git

# Verify the new remote named ‘upstream’
git remote -v

Whenever you want to update your fork with the latest upstream changes, you’ll need to first fetch the upstream repo’s branches and latest commits to bring them into your repository:

# Fetch from upstream remote
git fetch upstream

# View all branches, including those from upstream
git branch -va

Now, checkout your own master branch and merge the upstream repo’s master branch:

# Checkout your master branch and merge upstream
git checkout master
git merge upstream/master

If there are no unique commits on the local master branch, git will simply perform a fast-forward. However, if you have been making changes on master (in the vast majority of cases you probably shouldn’t be, you may have to deal with conflicts. When doing so, be careful to respect the changes made upstream.
Now, your local master branch is up-to-date with everything modified upstream.
Doing your work

Create a branch

Whenever you begin work on a new feature or bugfix, it’s important that you create a new branch. Not only is it proper git workflow, but it also keeps your changes organized and separated from the master branch so that you can easily submit and manage multiple pull requests for every task you complete.
To create a new branch and start working on it:

# Checkout the master branch – you want your new branch to come from master
git checkout master

# Create a new branch named newfeature (give your branch its own simple informative name)
git branch newfeature

# Switch to your new branch
git checkout newfeature