## glossary

What is Branch?

A branch is an independent line of development inside a Git repository. It lets you work on a feature or a fix without affecting the main code, isolating changes until they are ready to be integrated.

Technically, a branch in Git is just a movable pointer to a commit — a file of a few bytes. That is why creating branches is instant and cheap, unlike older systems where branching copied the entire project.

A branch is a pointer that advances with each commit
        A---B---C  feat/carrinho
       /
  D---E---F---G  main

# The feat/carrinho branch started from commit E.
# main moved on to F and G independently.
# Nothing in feat/carrinho affects main until integration.

Essential operations

Creating, switching and integrating
git branch                   # lists local branches
git switch -c feat/carrinho  # creates and switches to the new branch
git switch main              # goes back to the main branch
git merge feat/carrinho      # integrates the changes
git branch -d feat/carrinho  # deletes it after integrating

git push origin --delete feat/carrinho  # deletes it on the remote

Branching strategies

  • Git Flow — fixed develop, release and hotfix branches alongside the main one. Structured, suited to products with versions and release windows.
  • GitHub Flow — just main and short-lived feature branches, integrated via pull request. Simple and aligned with continuous deployment.
  • Trunk Based Development — everyone integrates into the main branch several times a day, with branches living for hours. Requires good test coverage and feature flags.

The current trend favors short-lived branches. The longer a branch lives in isolation, the more divergence it accumulates and the more painful the integration — exactly the problem that continuous integration exists to prevent.

Conflicts: why they happen and how to resolve them

A conflict arises when two branches change the same lines of a file and Git cannot decide which version to keep. It marks the section and hands the decision over to you.

The conflict markers in the file
<<<<<<< HEAD
const desconto = calcularDesconto(total, 0.10);
=======
const desconto = total * 0.15;
>>>>>>> feat/promocao

# Edit the file keeping what should stay,
# remove the markers, and then:
git add arquivo.ts
git commit

How to reduce conflicts

Integrate the main branch into yours frequently, instead of accumulating divergence for weeks. Keep branches small and focused. And agree with your team on how to split the work so that two people do not rewrite the same file at the same time — most conflicts are about coordination, not tooling.

## faq

Frequently asked questions

What is the difference between git switch and git checkout?

git checkout is the older command and piles up unrelated jobs: switching branches and restoring files. To reduce the confusion, Git introduced git switch (switch branches) and git restore (restore files). checkout still works, but the newer commands are clearer.

Should I delete the branch after the merge?

Yes. The commit history remains in the main branch, so nothing is lost. Keeping already-integrated branches around only clutters the list and makes it harder to see what is actually in progress. Platforms like GitHub offer automatic deletion after the merge.

What is a protected branch?

It is a platform setting that blocks direct pushes to critical branches like main, requiring a pull request, approvals and passing CI checks before the merge. It is the standard way to guarantee nothing reaches production without review.