fatal: invalid reference (Git) — how to fix
fatal: invalid reference: feature/login
fatal: invalid reference: origin/develop
Quick fix: Run git fetch origin and look for the name with git branch -a. Then create the branch from the remote one: git switch -c feature/login origin/feature/login. For worktrees use git worktree add -b new-branch ../dir origin/main. In single-branch clones run git remote set-branches origin '*' first.
What it means
Commands that take a start point — git checkout -b <new> <start>, git switch -c <new> <start>, git worktree add <path> <branch>, git branch <new> <start> — resolve that start point to a commit. If no branch, tag or commit with that name exists in your local repository, Git stops with fatal: invalid reference: <name>.
"Local" includes remote-tracking branches like origin/develop, but only after they've been fetched.
Cause 1: the remote branch isn't fetched yet
Someone pushed a branch after you cloned or last fetched:
git fetch origin
git branch -r | grep login
git switch -c feature/login origin/feature/login
On Git 2.23+ you can also let git switch create the tracking branch automatically when exactly one remote has that name:
git switch feature/login
Cause 2: typo or wrong case
Branch names are case-sensitive (Feature/Login ≠ feature/login), and slashes matter. List everything Git knows:
git branch -a
git tag -l
git ls-remote --heads origin # what the server actually has
If git ls-remote doesn't list it, the branch doesn't exist on the remote (deleted, merged, or never pushed).
Cause 3: git worktree add
git worktree add ../hotfix hotfix-123
# fatal: invalid reference: hotfix-123
The last argument must be an existing branch or commit. To create a new branch for the worktree, use -b and give a start point:
git worktree add -b hotfix-123 ../hotfix origin/main
To check out an existing remote branch in a worktree, fetch first, then:
git worktree add ../login feature/login
A branch can be checked out in only one worktree at a time; that gives a different error, explained in branch is already checked out at worktree.
Cause 4: single-branch or shallow clone
git clone --single-branch and git clone --depth 1 (which implies single-branch) configure the remote to fetch only one branch, so git fetch never brings the others. Check:
git config --get-all remote.origin.fetch
# +refs/heads/main:refs/remotes/origin/main
Widen it and fetch:
git remote set-branches origin '*'
git fetch origin
CI systems often make such clones. In GitHub Actions, actions/checkout with fetch-depth: 0 fetches all branches and tags.
Cause 5: the remote has a different name
Your remote might be upstream rather than origin:
git remote -v
git switch -c feature/login upstream/feature/login
Cause 6: a commit hash or tag that isn't local
A SHA from a PR or another clone exists only after fetching it. Tags need fetching too:
git fetch origin --tags
git fetch origin <full-sha> # works on servers that allow fetching by SHA, e.g. GitHub
git switch -c test <sha>
Last updated 2026-12-05.