Branch VS Fork

If I work with a team on a project on GitHub. And I want to make edits to the project. Should I make a new branch for the edition or make a new fork ?

Please note that the team has right access on the repository so any member have to option to branch/fork.

  • Branch supporters (from our team):
    • From GitHub Learning Lab course managing-merge-conflicts we understood that edits comes as branches and then make a pull requests to the master (or to primary branch if it is not master) and then delete the branch after merging (or close and stop working on it).
    • And this link says the same: github-glossary/#branch
    • This page too about-branches says that:

You can use branches to:

  • Develop features
  • Fix bugs
  • Safely experiment with new ideas
  • Some video about GitHub (I think they were from GitHub itself) said that you use branches for edits then merge then delete (I don’t have the link for the video)
  • Fork supporters (from our team):
    • Users with right access to the repository, who can make branches, can also edit the branches of the other team members without the other memmber’s consent , while making a fork deny such an edition withiout permission of fork owner (even if we, in our team, don’t mess our each others work, it stills available).
    • Alot of known companies on GitHub use brnaches to provide the code for different versions of the project, while using forks for editing.

So should we use branches or forks for editing the project ?

6 Likes

There’s no right or wrong way to do it if it achieves your goals. But, the most common ways people use branches and forks for collaboration is:

  • People who are members of the organization use branches in the organization’s repository
  • People who are not members of the organization use branches in forks of the organization’s repository

So, for example, I am a member of the Atom organization. When I want to suggest a change to anything in the Atom project, I create a branch locally, work on my changes, then push the branch to the GitHub-hosted repo, and open a pull request. However, I am not a member of the Kubernetes organization. If I wanted to  suggest a change to something in the Kubernetes project, I would create a fork. But still I would create a branch locally in that fork, work on my changes, then push the branch to the GitHub-hosted repo, and open a pull request.

I hope that helps!

36 Likes

Thank you @lee-dohm. This is a beautiful explanation. Elegant yet simple.

1 Like