DEV Community

Jenna Toff
Jenna Toff

Posted on • Originally published at jennatoff.Medium

To Branch or Not To Branch?

As I’ve been learning more about development, and working with different groups of people: branches in terms of git are foreign concepts to many people, especially those just starting out.

Is branching necessary? No, not really. If you’re working on your own you can easily manage your own changes and just use the main branch. If you’re only pushing changes once you’re done with a section, it’s similar to merging a section of content. If you make a mistake somewhere, or other changes were made you can stash the changes you made and pull where you can bring back or disregard what you stashed. It isn’t the most ideal situation, but it works.

Why branch?

  • Branches are really great organizational tools. Theoretically you can create an unlimited amount of branches and use one for anything you’re working on.
  • Branches are segregated. If you’re working on a couple features at once, having different branches for each will allow you to work on one without any bugs from another effect your environment.
  • Great for working in teams: each person can work in their own branches and save Main for things that have been tested to work.

Branches are also good for use with Pull Requests (PR): request for code to be merged into the main code (or other branch in the repository).

If you’re working on a group project or in open source: owners are often the only ones that are capable of merging some changes into the Main. Collaborators can work directly with the repository but would need to use branches to stage their changes and make a PR to have them incorporated. If you aren’t authorized as a collaborator, you can fork the repository and make a PR from anywhere in your forked repository (the main, or a branch) to the original repository.

As you work with larger bodies of code, and with more people: using Git Branches becomes an even more ideal part of your workflow, and can actually become necessary to use. Try learning about using Git Branches early!

Top comments (0)