Forking a GitHub Repository and Using Pull Requests

Category
Drupal Version
Tags

Forking creates a copy of a repository which you can work on. You can then submit a pull request to have your changes reviewed and integrated with the master repo. This is the order of operations:

FORK > SYNC > BRANCH > COMMIT > PUSH > PULL REQUEST

Download a PDF version of this guide.

Forking a Repository

Reference: https://help.github.com/articles/fork-a-repo/

In Github, navigate to the repository to be forked and select “Fork” on the upper right. Select your own user name when prompted. This creates a copy of the repository for you on Github.

Now you should see your fork. Copy the URL using this button:

Open Terminal and type:

git clone https://github.gatech.edu/ORG_NAME/Repo-Name

Here (after clone) you should paste the URL you copied at the beginning of this step. This creates a local copy of your clone on your machine under your current directory.

Connect your Fork to the Master

Next, sync your fork with the master to ensure that any changes going on with the master will be reflected in your local fork/clone.

Navigate in Github to the original repository. Copy the URL as shown:

  • Open Terminal and change directories to the fork you cloned.

    cd (enter)
    ls (look for your cloned fork/repository name)
    cd Fork_Name
    git remote -v

    git remote add upstream https://github.gatech.edu/ORG_NAME/Repo-Name

  • Alternately, you can both add and fetch (sync with) your master by using this instead:

    git remote add -f upstream https://github.gatech.edu/ORG_NAME/Repo-Name

  • Verify your upstream repository is syncing.

    git remote -v

Syncing Your Fork

Reference: https://help.github.com/articles/syncing-a-fork/

You probably want your fork to mirror the latest changes being made to the main repository. If you used “git remote add -f upstream” in the previous step, this is already done. If you used “git remote add upstream” and now you need to fetch upstream to sync your fork, you can use this method.

  • In Terminal, change to the directory of your local clone and fetch upstream to sync with the original master repository.

    cd Fork_Name
    git fetch upstream
  • Check out your fork’s local master branch.

    git checkout master
    git merge upstream/master

Branch Your Fork

Now Branch your issue locally.

In Terminal:

git checkout -b name_of_your_new_branch

Committing Changes to Your Fork

  • Change your files as needed.

  • In Terminal,

    git status

    This will confirm that git is watching your modifications.

  • Add the files to staging (substitute your file name or names)

    git add path/file_name

  • Then commit

    git commit -m “First commit”

You will get feedback saying how many files were changed and how.

Note for newbies: A branch may contain many commits. Name your branch to reflect what you’re working on and name commits to reflect more specific changes.

Pushing Your Changes to GitHub

In Terminal,

git push origin name_of_your_new_branch

Now you should see your branch show up in Github.

Making a Pull Request

Reference: https://help.github.com/articles/using-pull-requests/

  • Select your branch in Github. Select “New pull request”

    You can enter details about the changes you are suggesting. You can also select a branch to send the request to, if it’s not the master branch.

  • When you’re ready, select “Create pull request” at the bottom.

    After you send a pull request, any commit that’s pushed to your branch will be automatically added to your pull request, which is useful if you’re making additional changes.