Branching

8

questions

How do you name branches?

By type and task: feature/cart-update, fix/price-rounding, hotfix/1.2.1, often with a ticket number — feature/123-cart-update. The prefix is visible right in the branch list and can be used in CI and branch protection rules.

How do you resolve conflicts?

git status shows the conflicted files. In each one I work through the <<<<<<<, =======, >>>>>>> markers: what each branch changed and why, and keep the right version — often a combination of both. I remove the markers, run the tests, then git add and git commit. For complex cases — the merge tool in the IDE.

How do you undo a merge that went wrong?

While the merge isn't finished — git merge --abort restores the starting state. If the merge commit is already created but not pushed — git reset --hard ORIG_HEAD. If it's already pushed — git revert -m 1 <merge-hash>.

How is git switch different from git checkout?

git checkout does too much: it both switches branches and restores files, so it's easy to make a mistake. Git 2.23 split it into git switch (branches only) and git restore (files only). Same result, unambiguous commands.

What is a detached HEAD?

A state where HEAD points to a specific commit rather than a branch — for example after git checkout <hash> or checking out a tag. New commits in this state don't belong to any branch and are easy to "lose" after switching. To keep the work — git switch -c <name>.

What is a Git branch technically?

A file with a commit hash in .git/refs/heads/ — a lightweight movable pointer. After a new commit, Git simply writes that commit's hash into it. That's why creating a branch is instant and copies nothing.

What's the difference between fast-forward and a merge commit?

Fast-forward is possible when the target branch has no new commits: Git just moves the pointer forward, the history is linear, no new commit. If the branches have diverged, Git creates a merge commit with two parents that joins both histories.

When should you use –no-ff?

When it matters to see in history that a set of commits was a separate feature: the merge commit groups them and lets you revert the whole feature with a single git revert -m 1 <hash>. Feature branches are often merged into main or develop this way.