# Git Branches and HEAD

> What a branch is, why making one costs almost nothing, and why most repos call the home branch main. How HEAD shows where you are standing.

**Course:** [Git and GitHub](https://learn.benibix.com/learn/development-version-control)  
**Time:** 12 min

**After this lesson you can:**

- Make a branch and switch to it
- Explain what the main branch is for
- Get out of a detached HEAD

## What a branch is, and how HEAD follows you

A branch is a separate line of work inside one repository. You make one to try a change while the main line stays safe. In Git, a branch is only a label: a tiny file holding one 40-character commit hash. So making a branch is instant, however big the project is. Git switch -c makes one and moves you onto it.

When you commit on a branch, its label moves forward to the new commit. The other labels stay where they were. So two people can work on two branches at once, and neither sees the other's half-done work until it is joined back.

The main branch is the home branch of a repo. New branches start from it, and finished work comes back to it. Most teams call it main. Older projects often call it master, which was Git's default name for years. Git still uses master unless you set it, and plans to switch to main in Git 3.0.

A feature branch is a short branch for one piece of work, like a new search box or one bug fix. You start it from main and commit to it as often as you like. When it works, you join it back into main and delete the branch. The work stays in main.

HEAD is Git's name for where you are standing. Most of the time it points at a branch, and the branch points at its newest commit. When you switch branches, HEAD moves with you, and Git swaps the files in your folder to match. The file .git/HEAD holds one line naming your branch.

You can also step onto an old commit by its hash, to see how the project looked then. Now HEAD points at a commit, not at a branch. Git calls this a detached HEAD. Looking around is safe. Committing there is risky, because no branch label moves forward to keep the new commits.

If you did commit in a detached HEAD, make a branch right there with git switch -c and a name. The new label then holds your commits, and nothing is lost. Switch away first, and those commits are left with no label. Git keeps them for a while, but they are hard to find.

The common mistake is a branch that lives for weeks. Main keeps moving while it waits. The longer the gap, the more lines both sides have changed, and the harder the join back. A branch of a day or two joins cleanly. A branch of a month can take an afternoon of fixes.

```console
$ git switch -c dark-mode
Switched to a new branch 'dark-mode'
$ git branch
* dark-mode
  main
$ cat .git/HEAD
ref: refs/heads/dark-mode
```
Make a branch and step onto it. The star and the HEAD file both say where you are.

![Three commits, A, B and C, sit in a line, with a label called main pointing at C. A fourth commit, D, branches off C, with a label called dark-mode pointing at it. Above that, a box called HEAD points at the dark-mode label, with a note saying where you are now. A note under D says a new commit moves only the dark-mode label.](https://learn.benibix.com/diagrams/dev-git-head.svg)

### Example: Lucy tries a new menu

Lucy wants to try a new menu on her café's website without breaking the live one. She runs git switch -c new-menu and makes 6 commits over two days.

Her main branch still matches the live site the whole time. The owner says yes, so she joins the branch back. Had he said no, she would delete one label and lose nothing on main.

**Words in this lesson:** [Branch](https://learn.benibix.com/term/development/branch), [Main Branch](https://learn.benibix.com/term/development/main-branch), [Feature Branch](https://learn.benibix.com/term/development/feature-branch), [Git HEAD](https://learn.benibix.com/term/development/head)

**Question:** What happens to main when I commit on another branch?

**Answer:** Nothing: main stays on the commit it was on. Only the label you are on moves forward. Main keeps pointing at the same commit until you join your branch back into it.

---

Source: https://learn.benibix.com/learn/development-version-control/git-branches-and-head
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
