A branch in Git is simply a lightweight, movable pointer to a commit. When you create a new branch, Git does not copy your entire project. It just creates a new pointer that you can move independently of other branches. That is what makes branching in Git so fast and cheap compared to other version control systems.
Every Git repository starts with a default branch. Historically this was called master, but modern Git defaults to main. The default branch is not special in any technical sense — it is just the branch that git init creates for you.
Git also has a special pointer called HEAD. HEAD tells Git which branch you are currently working on. When you switch branches, HEAD moves to point at the new branch, and Git updates the files in your working directory to match.
Think of branches as parallel timelines. Each branch can evolve independently, and you can merge them back together when you are ready.
Because branches are just pointers, they cost almost nothing to create. A single 41-byte file is all Git needs for a new branch. This means you should create branches freely — one per feature, one per bugfix, one per experiment. If the experiment fails, you delete the branch and nothing is lost from your main line of work.
Creating branches
There are two common ways to create a branch. The first creates the branch without switching to it:
Create a branch
$ git branch feature/login
Hover over each part to see what it does
The command above creates a new branch pointer at your current commit but leaves HEAD on whatever branch you were on. Your working directory does not change.
More commonly, you want to create a branch and switch to it in one step. The classic way is git checkout -b:
Create and switch in one step
$ git checkout -b feature/login
Hover over each part to see what it does
With Git 2.23 and later you can also use the newer git switch -c syntax, which does exactly the same thing:
bash
git switch -c feature/login
The -c flag stands for create. Both approaches produce an identical result — pick whichever feels more natural to you.
Branch naming conventions
Using slashes in branch names is a widely adopted convention that groups related branches into folders. Common prefixes include:
feature/ — new functionality (e.g. feature/login, feature/dark-mode)
bugfix/ — bug fixes (e.g. bugfix/null-pointer)
hotfix/ — urgent production fixes
release/ — release preparation branches
These prefixes are not enforced by Git. They are simply a team convention that keeps your branch list organized, especially as the number of branches grows.
Switching branches
Once a branch exists, you need to switch to it to start working on it. Git provides two commands for this.
git switch (recommended)
The git switch command was introduced in Git 2.23 specifically for switching branches. It has a clear, focused purpose:
Switch between branches
git switch will refuse to switch if you have uncommitted changes that would conflict with the target branch. This is a safety feature — it prevents you from accidentally losing work.
git checkout (the classic way)
Before git switch existed, git checkout was the only way to switch branches:
Switch with checkout
The reason the Git team introduced git switch is that git checkout does too many things. It switches branches, restores files, detaches HEAD, and more. The newer commands split these responsibilities:
git switch — for switching branches
git restore — for restoring files
Both git switch and git checkout work fine for switching branches. If you are learning Git for the first time, prefer git switch for its clarity. If you are already comfortable with git checkout, there is no need to change your habits.
Listing branches
To see all your local branches, run git branch with no arguments:
List local branches
The asterisk (*) marks the branch you currently have checked out — that is where HEAD points.
To see remote-tracking branches as well, add the -a flag (short for --all):
List all branches (local + remote)
Remote-tracking branches appear with the remotes/origin/ prefix. These are read-only references that Git updates when you fetch or pull. You cannot commit directly to them — they mirror the state of branches on the remote server.
A few other useful listing options:
git branch -v — shows the latest commit on each branch
git branch --merged — lists branches already merged into the current branch (safe to delete)
git branch --no-merged — lists branches with work not yet merged
Deleting branches
After a branch has been merged, you typically want to clean it up. Git gives you two options with different safety levels.
Safe delete with -d
The lowercase -d flag only deletes a branch if it has been fully merged into the current branch or its upstream:
Safe delete
This is the recommended approach. Git checks that no commits would be lost and refuses if they would.
Force delete with -D
Sometimes you want to discard a branch that was never merged — for example, a failed experiment. The uppercase -D flag forces deletion regardless of merge status:
Force delete
Use -D with care. Once you delete an unmerged branch, the commits on it become unreachable. They still exist in the object database for a while (recoverable via git reflog), but they will eventually be garbage collected.
A good habit: always try -d first. If Git complains, think twice about whether you really want to lose those commits before using -D.
Visual branch management in Komitly
Managing branches from the command line works, but once your project has more than a handful of branches, a visual interface makes navigation significantly easier. Komitly groups branches into folders automatically based on the slash convention, so feature/auth and feature/ui appear under a collapsible feature folder.
Komitly — Branch Sidebar
Branches (4)
●mainHEAD
▸feature
●auth
●ui
▸bugfix
●typo
f7a91c2Add login page stylesfeature/auth
e6b82d1Fix button alignmentfeature/ui
d5c73e0Fix typo in READMEbugfix/typo
c3d4e5fRelease v1.0.0main
b2a1f6eAdd user model
a1b0c9dInitial commit
The sidebar on the left shows your branches grouped by prefix. The active branch is highlighted and marked with HEAD. The commit graph on the right shows how each branch diverges from main — each colored lane represents a different branch.
Komitly lets you perform common branch operations directly from the sidebar without opening a terminal:
Create a branch — right-click any commit in the graph and select "Create branch from here"
Switch branches — double-click a branch name in the sidebar
Delete a branch — right-click a branch and choose "Delete branch" with a confirmation prompt
Rename a branch — right-click and choose "Rename"
Hide branches — toggle the eye icon to hide a branch from the graph without deleting it
The branch folder grouping is especially helpful in repositories with dozens of branches. Instead of scrolling through a flat list, you can collapse entire groups you are not working on and focus on the ones that matter.
Komitly also detects stale branches — branches that have not been committed to in a configurable number of days. This makes cleanup easy: open the stale branches panel, review which ones are fully merged, and delete them with a click.
Summary
Here is a quick reference of the branch commands covered in this article:
Branches are one of the most powerful features in Git. They let you work on multiple things in parallel, experiment without risk, and collaborate with teammates without stepping on each other's toes. Whether you manage them from the terminal or from a visual tool like Komitly, the underlying concepts are the same — and now you know them all.