fatal: Not a valid object name
Git’s fatal: Not a valid object name error means you referenced a commit, branch, tag, or other object that doesn’t exist in your repository’s object database.
What It Means
Git stores everything — commits, trees, blobs, tags — as objects identified by a SHA-1 hash (a 40-character hex string). When you run a command that requires a valid object reference (a branch name, commit hash, or tag), Git looks it up in its internal database. If it can’t find it, Git reports that the name isn’t a valid object.
Why It Happens
- You typed a commit hash incorrectly (missing characters, wrong branch).
- The branch name doesn’t exist yet (you haven’t made the first commit, or you misspelled the name).
- You’re referencing a commit from a different repo or a remote that hasn’t been fetched.
- The commit was garbage-collected or the repository is corrupted.
- You ran
git checkoutwith a name that doesn’t match any branch, tag, or commit.
How to Fix It
1. Verify the reference exists
List all branches:
git branch -aList all tags:
git tagView recent commits with their full hashes:
git log --oneline -102. Check for the first commit
A common cause: you created a repo with git init but haven’t committed anything yet. Branches don’t exist until the first commit:
git status # see if there are files to commit
git add .
git commit -m "Initial commit"After the first commit, git branch will show main (or master).
3. Fetch remote branches
If the branch exists on the remote but not locally:
git fetch origin
git checkout <branch-name>4. Use the full or partial commit hash
# Use enough of the hash to be unique (7+ characters)
git show abc1234
# Or the full 40-character hash
git show abc1234def5678...etc5. Check for orphan branches
If you used git checkout --orphan <branch>, that branch has no commits. Make a commit first, then the branch name becomes a valid reference.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro