Home › Git

fatal: a branch named 'feature' already exists (Git) — how to fix

$ git checkout -b feature
fatal: a branch named 'feature' already exists

Quick fix: To use the existing branch: git switch feature. To reset it to your current commit (discarding what it pointed to): git switch -C feature or git checkout -B feature. To keep both, pick another name or rename the old one with git branch -m feature feature-old.

What it means

Branch names in a repository are unique. git checkout -b <name>, git switch -c <name> and git branch <name> all create a branch, and refuse when refs/heads/<name> already exists. Often you created it earlier and forgot, or a tool or IDE created it for you.

List what exists and where it points:

git branch -vv
git log --oneline -3 feature

Fix 1: you just want to work on it

Switch to the existing branch instead of creating it:

git switch feature
# or
git checkout feature

Fix 2: recreate it at the current commit

If the old branch is obsolete and you want feature to point at where you are now (or at another start point), force it:

git switch -C feature              # reset/create at HEAD and switch
git switch -C feature origin/main  # reset/create at origin/main

Older equivalent:

git checkout -B feature origin/main

Without switching:

git branch -f feature origin/main

git branch -f refuses to move the branch you have checked out; use git reset on it instead.

This discards the commits that only the old feature had. They're still reachable for a while through git reflog, but check first:

git log --oneline origin/main..feature    # commits you'd lose

Fix 3: keep the old branch under another name

git branch -m feature feature-old
git switch -c feature

Fix 4: delete the old branch

git branch -d feature     # only if it's fully merged
git branch -D feature     # force delete

You can't delete the branch you're currently on; switch away first.

Fix 5: tracking a remote branch with the same name

To check out a remote branch, you don't need -b at all. If no local branch exists yet, Git creates one that tracks the remote:

git fetch
git switch feature        # creates local feature tracking origin/feature

If a local feature already exists and you want it to match the remote:

git switch feature
git reset --hard origin/feature    # discards local changes and commits on it

Or just set the upstream without moving it: git branch -u origin/feature feature.

Case-insensitive file systems

On Windows and macOS, branch names that differ only by case (Feature vs feature) can collide because loose refs are stored as files. Pick names that differ by more than case, and use git branch -m to rename if you already have such a pair.

That is a different error: the branch exists and is checked out in another worktree. See git worktree list, and either work in that worktree or remove it with git worktree remove <path>.

Last updated 2026-11-29.