When should I use branches vs. forks when contributing to a repository? #212064
🏷️ Discussion TypeQuestion BodyI’m new to open-source contribution. Can someone explain when to create a branch in my own repo versus forking someone else’s, and how to keep a fork in sync with the original repository? |
Replies: 1 comment
|
Branch: Use it when you have write access to the repo (your own project or a team repo). Create feature/login, work, and open a PR into main. Keeping a fork in sync: On GitHub, click Sync fork on your fork’s page, or Always create a new branch from an up-to-date main for each contribution. |
Branch: Use it when you have write access to the repo (your own project or a team repo). Create feature/login, work, and open a PR into main.
Fork: Use it when you don’t have write access, as in most open-source contributions. A fork is your own copy of someone else’s repo, where you push branches and then open a PR back to the original.
Keeping a fork in sync:
On GitHub, click Sync fork on your fork’s page, or
From the command line:
bash
git remote add upstream https://github.com/ORIGINAL/REPO.git
git fetch upstream
git checkout main
git merge upstream/main # or: git rebase upstream/main
git push origin main
Always create a new branch from an up-to-date main for each contribution.