Back
GitoryxGitoryx
Beginner9 min read

Git Branch: Create, Switch, and Manage Branches

Branches are the foundation of every Git workflow. This tutorial covers creating and switching branches, understanding HEAD, deleting stale branches, and working with remote branches — all with practical examples.

The Problem

You've been committing directly to `main` and now two features are tangled together. Or you're afraid to experiment because any mistake will affect the working code. Branches solve both of these problems.

Branches are the core of any Git workflow. They let you develop features, fix bugs, and experiment in complete isolation — without touching the stable codebase. Every pull request starts with a branch.

Common mistakes developers make with this:

  • Working directly on `main` instead of a feature branch
  • Forgetting to switch branches before starting new work
  • Leaving dozens of stale merged branches that clutter the repo
  • Confusing local branches with remote tracking branches

Gitoryx: Gitoryx shows all your branches in the sidebar and the commit graph simultaneously. Creating, switching, and deleting branches is a single right-click.

What is Branch: Create, Switch, and Manage Branches?

A Git branch is a lightweight, movable pointer to a specific commit. Creating a branch doesn't copy files — it just creates a new pointer that advances independently as you commit. The default branch is usually called `main` or `master`.

Step-by-Step Guide

1

List your branches

See all local branches. The `*` marks your current branch.

bash
git branch

# * main
#   feature/login
#   bugfix/header-typo

Use `git branch -a` to list remote tracking branches too.

2

Create a new branch

This creates the branch but does NOT switch to it.

bash
git branch feature/user-auth
3

Create a branch and switch to it immediately

This is the most common pattern — create and switch in one command.

bash
# Modern Git (2.23+)
git switch -c feature/user-auth

# Classic syntax (still works everywhere)
git checkout -b feature/user-auth
4

Switch to an existing branch

Move to a branch that already exists.

bash
git switch feature/user-auth
# or:
git checkout feature/user-auth

Make sure to commit or stash your current changes before switching — Git may refuse to switch if there are conflicts with the target branch.

See this workflow in Gitoryx — Gitoryx screenshot

See this workflow in Gitoryx. All branches shown in the sidebar with their latest commit

Free download
5

Rename a branch

Rename your current branch or a different local branch.

bash
# Rename the current branch
git branch -m new-name

# Rename a specific branch
git branch -m old-name new-name
6

Delete a branch

Clean up branches that have been merged. Use `-d` for a safe delete (fails if unmerged), `-D` to force.

bash
# Safe delete (only if merged)
git branch -d feature/user-auth

# Force delete
git branch -D feature/user-auth

# Delete a remote branch
git push origin --delete feature/user-auth

Common Mistakes to Avoid

Committing to `main` directly

This makes it impossible to open a proper pull request and risks pushing unstable code to the shared branch.

Fix: Always create a new branch for any change — even a one-line fix. Branch names like `fix/button-color` cost nothing.

Not pulling before creating a branch

If your local `main` is behind the remote, your new branch starts from outdated code.

Fix: Run `git pull origin main` before branching to make sure you're starting from the latest code.

Accumulating stale branches

After merging a PR, the feature branch lingers indefinitely. Over time the repo fills with dozens of dead branches.

Fix: Delete branches after merging. GitHub and GitLab can auto-delete branches when a PR is merged.

Gitoryx — visual Git client for macOS, Windows & Linux
GitoryxGitoryx — macOS, Windows & Linux

Create and manage branches visually in Gitoryx

  • All branches shown in the sidebar with their latest commit
  • Create or switch branches with a single right-click in the graph
  • See diverged branches at a glance with the visual commit graph
  • Delete merged branches in bulk from the branch manager
Download Gitoryx — FreemacOS · Windows · Linux · No subscription

Frequently Asked Questions

What is the difference between `git branch` and `git checkout -b`?

`git branch <name>` creates a branch but stays on the current branch. `git checkout -b <name>` (or `git switch -c <name>`) creates a branch and immediately switches to it. The latter is what you usually want.

How do I see all branches including remote ones?

Run `git branch -a`. Local branches appear in white; remote tracking branches appear in red (or prefixed with `remotes/origin/`).

What happens when I delete a branch?

Deleting a branch only removes the pointer — the commits themselves remain in the repository until Git garbage-collects them. As long as the branch was merged, the history is preserved in the target branch.

Can I work on multiple branches at the same time?

Not in the same working directory. You can only have one branch checked out at a time. However, Git worktrees let you check out multiple branches simultaneously in separate folders.

See it in action with Gitoryx

Everything in this tutorial is faster and clearer with a visual Git client. Gitoryx is free, runs natively on macOS, Windows, and Linux, and built for developers who want to move fast without breaking things.