GitHub Forking (workflow)

MD
S
Markdown

This tutorial explains on how to fork from GitHub and help you work on community projects. Based on: https://gist.github.com/Chaser324/ce0505fbed06b947d962

Workflow

Clone

git clone git@github.com:USERNAME/FORKED-PROJECT.git

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

Fetch from upstream remote

git fetch upstream

View all branches, including those from upstream

git branch -va

Checkout your master branch and merge upstream

git checkout master git merge upstream/master

Begin work on a new feature or bugfix, you MUST create a new branch.

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

Make changes


Fetch upstream master and merge with your repo's master branch

git fetch upstream git checkout master git merge upstream/master

If there were any new commits, rebase your development branch

git checkout newfeature git rebase master

Rebase all commits on your development branch

git checkout git rebase -i master

Commit and Push all of your changes to GitHub

Go to the page for your fork on GitHub, select your development branch, and click the pull request button

For the Origin Remote Owner

Checking Out and Testing Pull Requests

Open up the .git/config file and add a new line under [remote "origin"]:

fetch = +refs/pull//head:refs/pull/origin/

Fetch all pull request branches

git fetch origin

Checkout out a given pull request branch based on its number

git checkout -b 999 pull/origin/999

Manually Merge a PR

Checkout the branch you're merging to in the target repo

git checkout master

Pull the development branch from the fork repo where the pull request development was done.

git pull https://github.com/forkuser/forkedrepo.git newfeature

Merge the development branch

git merge newfeature

Push master with the new feature merged into it

git push origin master

Delete branch

git branch -d newfeature

Created on 4/22/2019