DEV Community

Cover image for Understanding Git Branches (Illustrated)
Erika Heidi
Erika Heidi

Posted on • Updated on

Understanding Git Branches (Illustrated)

In a previous post, we talked about the process of submitting changes to a remote Git repository. We've seen that this process is done in three steps: 1) stage. 2) commit. 3) push.

In a small project with a solo contributor, it's not uncommon that these changes are pushed directly into master. But when multiple developers need to work in the same Git repository, it is important to define a process that leverages parallel collaboration. That's when branches become essential.

Git Tree Illustration

Not all trees are the same, but they all start small. In a typical Git repository, code grows as a tree. Features are implemented in development branches that are eventually merged into a master branch.

Whenever working on a team, whether if it's in an open source project or a corporate setting, it's always a good practice to create a new branch (usually based on master) and start from there.

Once you're finished with your changes, you can then push your branch to the remote repository and create a new pull request. A pull request is a formal request for merging your branch into master.

Pull Request Mando and Baby Yoda

Although it is possible to push and merge a branch directly into "master", creating a pull request is usually the way to go when suggesting changes in a codebase.

Opening a pull request creates an opportunity for code review and actionable feedback; that's why it became a standard procedure for collaborating in most open source projects.

For a more in-depth understanding of Git branches, please check these docs or have a look at this quick reference guide.

Any Git topic you'd like to understand better? Leave your suggestion for my next comic in the comments :)

Top comments (11)

terabytetiger profile image
Tyler V. (he/him)

Wow! These illustrations are incredibly well done - both informative and gorgeous!

erikaheidi profile image
Erika Heidi • Edited

thank you <3

richardeschloss profile image
Richard Schloss • Edited

Great illustrations. I think illustrations on "merging" vs. "rebasing" may help teams out a lot (and explaining how to resolve merge conflicts); since the last paragraph discussed merge requests, it may be an appropriate place to continue. Thanks for doing this.

jeastham1993 profile image
James Eastham

Hey Erika, great post! Especially your point on always using pull requests when suggesting changes in a code base!

aleksandrhovhannisyan profile image
Aleksandr Hovhannisyan

Beautiful drawings!

But the post is too short, imo, and doesn't do a good job of explaining branching in git (that's what I expected the post to do based on the title).

It's more about why/when branches are used.

erikaheidi profile image
Erika Heidi

Thank you for your feedback, these are really aimed at beginners. I have added a few links for more comprehensive guides!

codypearce profile image
Cody Pearce • Edited

Awesome illustrations, what do you use to make them?

erikaheidi profile image
Erika Heidi

These were hand-drawn and painted with watercolors, than scanned for final touches. I can't find joy in digital arts!

zabithrafeek profile image
zabith rafeek

Could you make a article on 'rebase'?

waylonwalker profile image
Waylon Walker

Amazing illustrations

joshpuetz profile image
Josh Puetz

These illustrations are amazing: you have a gift! I’ll admit I came for baby Yoda 😀