Best practices

Use feature branches

A feature branch is any branch created to develop a specific feature or fix a specific bug.

Create a new branch for each feature or bug fix instead of working directly on the main branch.

Merge feature branches into main only when the feature is complete and tested. This keeps your work isolated and makes it easier to manage changes. With this approach, the main branch always contains stable code that is ready for production.

Suppose you have been tasked with implementing Facebook login in the client application.

Bad
  1. You start working on the feature right away, committing your changes directly to the main branch. By the end of the day, you have a few commits that partially implement the feature.
  2. Suddenly, you get a call from your boss, asking you to fix a critical bug with the existing login system and release it immediately.
  3. While the fix itself is trivial, you realize that if you release now, your half-finished Facebook login code will also be included in the release. Oopsie!

It gets even worse when working in a team. Imagine everyone working on the main branch: half-baked, in-progress code from different developers gets mixed together, making it impossible to figure out what is ready for release and what is not. This leads to confusion, broken builds, and wasted time.

Good
  1. You create a new branch called feature/facebook-login (or whatever) and start working on the feature there. You commit your changes to this branch, keeping the main branch clean and stable.
  2. If tasked with unexpected bug fixes, you switch to the main branch, create another branch called bugfix/login-issue, and implement the fix there. Once tested, that bugfix branch is merged into main. The release is deployed, everyone is happy.
  3. You switch back to your feature/facebook-login branch, do a git rebase to incorporate the latest changes from main into your feature branch, and continue working on the feature. When the feature is complete, you merge it back into main.
© 2024-2025 GitByBit.All rights reserved.

Hi! I'm Alex, creator of GitByBit.

And this is Gitopedia—a reference that summarizes knowledge in my Git course.

Gitopedia is designed to be a personal knowledge base. When you progress through the main Git course in VS Code, you unlock all of these topics, one by one, bit by bit. This gives you time to digest the information and gradually build the mental model of Git. Here's an example of how it works:

Learning directly in VS Code lets you practice Git exactly as you would in real life, doing real jobs, writing real code. In addition, the course has access to your actual terminal, so it can point out mistakes, suggest workarounds, etc.

The course is FREE, there are no Ads or other bullshit. There are optional premium add-ons you can purchase, mainly to support my work (regrettably, I have to eat every day), but that's totally up to you.

Learn Git in VS Code