Skip to content

Instantly share code, notes, and snippets.

@nicholashagen
Created March 15, 2012 01:56
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nicholashagen/2041175 to your computer and use it in GitHub Desktop.
Save nicholashagen/2041175 to your computer and use it in GitHub Desktop.
Working with GitHub Forks

The following code is day-to-day operations when working with 3 forks: an open source project, a local fork of that project, and a company fork of that project. The power of Git is remote aliases that allow you to work with all 3 forks in parallel in the same code base and instantly compare, push, merge, etc.

Setup:

#> git clone [url of local fork: ie: username/project]
#> cd project
#> git remote add project [url of project: ie: project/project]
#> git remote add company [url of company fork: ie: company/project]

At this point, there are 3 remotes: origin as the local fork, project as the open source repo, and company as the company fork.

Typically you will only push to the local branch and the company repo. Pull requests will be done through GitHub to push to the open source repo. To get started, you will need to create remote tracking branches for the local origin and the company.

#> git fetch company
#> git branch --track company-master company/master

We are now ready to do our day-to-day work.

#> git checkout master
#> git pull origin master

hack hack hack

#> git add [files...]
#> git commit 
#> git push origin master

Your local fork should now be updated. At this point, you can do a Pull Request on the open source project. Once it is merged into the open source project, you can merge it into the company branch.

#> git checkout company-master
#> git fetch project
#> git merge project/master
#> git push company company-master:master

All three forks should now be in sync again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment