List your branches
See all local branches. The `*` marks your current branch.
git branch
# * main
# feature/login
# bugfix/header-typoUse `git branch -a` to list remote tracking branches too.
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.
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:
Gitoryx: Gitoryx shows all your branches in the sidebar and the commit graph simultaneously. Creating, switching, and deleting branches is a single right-click.
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`.
See all local branches. The `*` marks your current branch.
git branch
# * main
# feature/login
# bugfix/header-typoUse `git branch -a` to list remote tracking branches too.
This creates the branch but does NOT switch to it.
git branch feature/user-authThis is the most common pattern — create and switch in one command.
# Modern Git (2.23+)
git switch -c feature/user-auth
# Classic syntax (still works everywhere)
git checkout -b feature/user-authMove to a branch that already exists.
git switch feature/user-auth
# or:
git checkout feature/user-authMake 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. All branches shown in the sidebar with their latest commit
Free downloadRename your current branch or a different local branch.
# Rename the current branch
git branch -m new-name
# Rename a specific branch
git branch -m old-name new-nameClean up branches that have been merged. Use `-d` for a safe delete (fails if unmerged), `-D` to force.
# 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-authThis 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.
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.
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.

`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.
Run `git branch -a`. Local branches appear in white; remote tracking branches appear in red (or prefixed with `remotes/origin/`).
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.
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.
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.