Preface
Contributing code to open-source projects can be done in two ways:
- Having write access to the repository, allowing direct pushes
- Not having write access, submitting changes through Pull Requests (PRs)
This article will briefly explain the PR workflow. For clarity, we'll use the following terminology:
- Open-source repository: Main repository
- Forked repository: Fork repository
Fork & Pull Request
Using the open-source project golang/go as an example, fork the open-source repository to your own account.
Fork Repository
Clone the forked repository to your local machine:
bash
$ git clone git@github.com:zhaiyuxin103/go.gitAfter completing your code changes, commit and save:
bash
$ git add -A
$ git commit -m "feat: something messages"
$ git pushMain Repository
Open your forked repository's homepage, click "New pull request", and submit your changes to the main repository.
Syncing Latest Code from Main Repository
bash
$ git remote add upstream https://github.com/golang/go.git
$ git fetch upstream
$ git merge upstream/masterTIP
Article republished from: How to Contribute Code to Open-Source Projects
