Forking a Repository
A fork is your own personal copy of someone else's GitHub repository. Forking is common for contributing to open-source projects you don't have direct write access to.
After forking, you clone your fork, make changes on a branch, push to your fork, and then open a pull request from your fork back to the original repository.
git clone https://github.com/your-username/forked-repo.git
git remote add upstream https://github.com/original-owner/repo.gitCreating a fork
Click the 'Fork' button on a GitHub repository page to create a full copy under your own account, which you can clone and modify freely.
Contributing back via pull request
After pushing changes to your fork, open a pull request comparing your fork's branch to the original repository's main branch, requesting your changes be merged upstream.
git clone https://github.com/alexsmith/awesome-project.git
git remote add upstream https://github.com/original-owner/awesome-project.gitClones your fork and adds the original repository as an 'upstream' remote to track its updates.
git fetch upstream
git merge upstream/mainFast-forward
README.md | 4 ++--Fetches the latest changes from the original project and merges them into your fork's local main branch.
Key points
- A fork is your own copy of someone else's repository.
- Forking is common for contributing to open-source projects.
- 'upstream' is the conventional name for the original repository's remote.
- Changes flow back via a pull request from your fork to the original repo.
