Branching is Git's superpower. In legacy version control systems like SVN, creating a branch was expensive and slow because it involved duplicating directory trees on a server. In Git, branching is instantaneous and virtually costless. Let's learn why.
In Git, a branch is not an isolated container of files. A branch is simply a lightweight, movable pointer to a specific commit object. That's it! It is literally a 41-byte plain text file inside .git/refs/heads/ containing the 40-character SHA-1 hash of the commit it points to.
Because creating a branch writes only 41 bytes to disk, creating, switching, and deleting branches in Git takes less than 1 millisecond regardless of whether your project contains 10 files or 100,000 files!
# List local branches (* indicates the currently active branch):
$ git branch
* main
feature/auth
bugfix/login-styles
# List both local AND remote-tracking branches:
$ git branch -a
# List branches with their latest commit SHA and title:
$ git branch -v
# Create a branch without switching to it:
$ git branch feature/user-profile
# Create a branch from a specific commit hash or tag:
$ git branch hotfix-v1.0 4b8e2a1
# Rename the currently active branch:
$ git branch -m modern-main
# Rename an arbitrary branch:
$ git branch -m old-name new-name
# Safe deletion (-d): Deletes branch ONLY if it has been fully merged into upstream:
$ git branch -d feature/auth
# Force deletion (-D): Deletes branch even if it contains unmerged commits:
$ git branch -D experimental-draft
Question: "What is the difference between git branch -d and git branch -D?"
Answer: "-d (lowercase) is a safety-checked deletion; Git prevents deleting the branch if it has unmerged work that would be lost. -D (uppercase) is a forced deletion equivalent to --delete --force, which discards unmerged commits without warning."
Strengthen your version control mastery by studying these connected classes:
Modern Git 2.23+ dedicated command for branch switching without side-effects.
Integrate completed feature branches into main via fast-forward and 3-way merges.
Handle overlapping code changes cleanly when two branches edit identical files.
Explore GitFlow, GitHub Flow, and Trunk-Based branch management models.
Advance your software engineering skills with the next topic in our synchronized curriculum.
Continue to git switch & checkout → Previous: ← File Management (mv & rm) | Full Syllabus