Skip to content

Instantly share code, notes, and snippets.

@TheDuriel
Last active September 17, 2019 18:08
Show Gist options
  • Save TheDuriel/0c27990e64ddbe6e4e53ea3ec7bfea77 to your computer and use it in GitHub Desktop.
Save TheDuriel/0c27990e64ddbe6e4e53ea3ec7bfea77 to your computer and use it in GitHub Desktop.

How to contribute to a Github project using forks, and pull requests.

Set up the fork:

  1. Fork the project on GitHub.
  2. Clone it to your computer using the terminal or a git client.
  3. Add the original project repository to your remotes
    • If you use the Source Tree git client this is done by clicking settings > remotes > add
    • If you use the GitKraken git client this is done by yada yada yada
    • Note that most git Clients will label your own Repository as origin when you first clone the repo. When you add a remote you can assign a custom name to it. (The owners github username for example.)
    • When managing remotes throug the terminal, you will be dealing with an origin and one or more upstreams. Refer to this page for details: https://hackernoon.com/sync-a-fork-from-upstream-repo-in-github-c2c29c8eca3b

Work on the project:

  1. Create a new Branch, and give it a name related to what you will be working on.
    • This new branch is where you will be making your changes.
    • Never commit to the auto generated Master branch. You will be using it for keeping up to date with the original repository.
    • Every time you want to work on a new feature. Create a new branch using the commit with the nameoforiginalprojectremote/master tag.
    • If you use the Source Tree git client this is done by right clicking the comit with the relevant name, and selecting create branch.
    • If you use the GitKraken git client this is done by yada yada yada
    • If you use the terminal, do this in one command with git checkout -b some-new-branch-name

Make a Pull request:

  1. Push your changes to your personal github repository. This is the origin remote.
  2. Got to the original project repositories github page.
  3. Click "new pull request"
  4. Select the relevant branch on your personal fork
  5. Add a description about the changes
  6. Submit and wait for approval. (Feel free to check out other PRs and comment on them!)

Update your fork:

  1. Perform a fetch with all tags.
    • If you use a git client. There will be a fetch button. Simply tick the all tags options before clicking Ok.
    • This ensures that you'r repository is aware of all changes that occured since you last updated your fork.
    • If you use the terminal, refer to this page https://git-scm.com/docs/git-fetch
  2. Make sure you have no uncommited changes.
    • If you do. This is the time to make a new branch and commit.
    • If you do not want to keep your changes, discard them.
  3. Switch over to the master branch of your fork.
  4. Perform a rebase using the original repositories master branch as the source.
    • In Source Tree this is done by rightclicking the commit with the nameoforiginalprojectremote/master tag and choosing rebase.
    • If you use the terminal, refer to this page: https://git-scm.com/docs/git-rebase
    • As long as you have not made any changes to your master branch, git will be able to perform a fast-forward rebase.
  5. Pull any missing commits.
    • In Source Tree this is done by clicking the pull button.
    • If you use the terminal, refer to this page.
  6. Update your fork with new commits from the project repository by the rebase technique
    • If you use the terminal, the command is git pull --rebase upstream master
    • If you use the Source Tree git client this is done by right clicking the latest commit with the / tag
    • If you use the GitKraken git client this is done by yada yada yada
  7. Gongraturations. You now have an up to date master branch. You can branch from it, and commit your changes, as described above.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment