How to contribute to a Github project using forks, and pull requests.
Set up the fork:
- Fork the project on GitHub.
- Clone it to your computer using the terminal or a git client.
- 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 moreupstream
s. Refer to this page for details: https://hackernoon.com/sync-a-fork-from-upstream-repo-in-github-c2c29c8eca3b
Work on the project:
- 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:
- Push your changes to your personal github repository. This is the
origin
remote. - Got to the original project repositories github page.
- Click "new pull request"
- Select the relevant branch on your personal fork
- Add a description about the changes
- Submit and wait for approval. (Feel free to check out other PRs and comment on them!)
Update your fork:
- 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
- If you use a git client. There will be a fetch button. Simply tick the
- 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.
- Switch over to the master branch of your fork.
- 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 choosingrebase
. - 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.
- In Source Tree this is done by rightclicking the commit with the
- Pull any missing commits.
- In Source Tree this is done by clicking the pull button.
- If you use the terminal, refer to this page.
- 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
- If you use the terminal, the command is
- Gongraturations. You now have an up to date master branch. You can branch from it, and commit your changes, as described above.