Skip to content
fatal: Not a valid object name

fatal: Not a valid object name

DodaTech 3 min read

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 checkout with 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 -a

List all tags:

git tag

View recent commits with their full hashes:

git log --oneline -10

2. 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...etc

5. 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.

What is a Git object?
A Git object is the internal data structure that stores content. There are four types: blob (file contents), tree (directory listings), commit (snapshot with metadata), and tag (named reference to a commit). Each object is identified by a SHA-1 hash. When you reference a name that doesn’t match any object, Git throws this error.
Can a corrupted .git folder cause this?
Yes. If the .git/objects/ directory is corrupted (disk error, partial copy, manual edits), existing commits may become unreadable. Run git fsck to check repository integrity: git fsck --full. If corruption is found, restore from a remote backup.
Does 'main' vs 'master' matter?
Yes — many repositories still use master as the default branch name. If your repo uses main but you type master (or vice versa), Git won’t find the branch. Run git branch to see the actual branch name, or git branch -a to see both local and remote branches.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro