Skip to content
86% off$349 $48.86code BF2026

Docs

Sledbot docs30 pages

fatal: ambiguous argument 'HEAD': unknown revision (fix)

Git says "fatal: ambiguous argument 'HEAD'" when a repo has no commits yet. Make one initial commit, verify it, and see which commands fail until then.

Updated 5 min read

On this page

You ran a command, a setup script or an agent tool in a brand-new project and got this:

text
fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree.

Git usually adds a hint line about using -- to separate paths from revisions. That hint is misleading here. Nothing is wrong with your path or your syntax.

Why it happens

git init creates a repository and a branch name, but not a commit. Until the first commit exists, HEAD is "unborn": it names a branch that has no commit behind it. Any command that has to resolve HEAD to a real commit has nothing to resolve.

Common causes, most frequent first:

  1. A new repo from an empty folder. You ran git init (or a tool did) and never committed. The error appears every time a command reads HEAD.
  2. A script that assumes a commit exists. Setup scripts and tooling often run git rev-parse HEAD, git diff HEAD, git log or a worktree command. Git exits with code 128, so a script that stops on the first error aborts at that line. People on a public issue tracker report exactly this when a project template creates a repo with no commit and the build then reads HEAD.
  3. Files added but not committed. git add . stages files, but staging does not create a commit. HEAD stays unborn.
  4. A commit that failed. A missing identity or a failing pre-commit hook can stop the commit, and you only notice later when something reads HEAD.

Git does not know your intent, so it reports the one thing it can: it cannot find a revision called HEAD.

Fix: make an initial commit

Run one of these in the repo folder.

Option 1: an empty first commit

This changes no files. It only gives HEAD something to point at.

bash
git commit --allow-empty -m "Initial commit"

Option 2: commit your existing files

bash
git add .
git commit -m "Initial commit"

Check your .gitignore first if the folder has build output or secrets, because git add . stages everything that is not ignored.

Verify it worked

bash
git rev-parse HEAD

A 40-character commit hash means HEAD now resolves. git log --oneline should show one line.

If git asks who you are

Git refuses to commit without a name and email. Set them and commit again:

bash
git config user.name "Your Name"
git config user.email "you@example.com"

These apply to this repo only. Add --global to set them for every repo on your Mac. To undo, run git config --unset user.name and git config --unset user.email (add --global if you set them globally).

Which commands fail on an unborn HEAD

CommandWith no commitsFix
git rev-parse HEADExits 128 with the ambiguous argument errorMake the first commit
git diff HEADSame errorMake the first commit, or use git diff --cached for staged changes
git logSays the current branch does not have any commits yetMake the first commit
git worktree addHas no commit to branch fromMake the first commit, then add the worktree
git statusWorks and says "No commits yet"Nothing to fix

The last row is a handy check. If git status says "No commits yet" followed by the branch name, you have confirmed the cause.

Why worktrees need a commit

A git worktree is a second checkout of the same repository on its own branch. That branch has to start from an existing commit, so a repo with no commits has nothing to branch from. This applies to any tool that creates worktrees, not only one app.

How Sledbot handles it

Sledbot's New task page has Work in a new worktree switched on by default for git repos, so a worktree needs a commit to start from. In New Project… (⇧⌘N, or File ▸ New Project…) two options give the project a HEAD from the start:

  • Start with set to Git repo has Make an empty first commit switched on by default.
  • Start with set to Template (Swift, Node, Python, Go or Rust) has Commit the files switched on by default.

Sledbot does not add a commit to a repo you created yourself. If you add a folder you ran git init in but never committed to, or you switched those options off, make the first commit with the commands above.

Checklist before you try again

  • You are inside the repo folder (git status does not say "not a git repository").
  • git status no longer says "No commits yet".
  • git rev-parse HEAD prints a hash.
  • Your script or tool runs in the same folder where you made the commit, not a different checkout.
  • No pre-commit hook rejected the commit.

If it still fails

Check these in order:

  1. Wrong folder. Run git status. "not a git repository" means you are outside the repo, which is a different problem.
  2. The commit didn't happen. Run git log --oneline. If git says the current branch does not have any commits yet, re-run the commit and read its full output.
  3. A pre-commit hook blocked it. Fix what the hook reports and commit again. Do not skip hooks as a habit.
  4. Another checkout. If your tool clones or copies the folder, the copy may have no commits even though the original has one.

If it still fails, ask the tool's maintainer or your team. Include the exact error text, the output of git status and git log --oneline, the command that failed, and your version from git --version. A message you can copy:

text
A command fails with:
fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree.

Repo created with: git init (no commits yet)
git status shows: (paste output)
git log --oneline shows: (paste output)
Command that failed: (paste command)
git --version: (paste version)
Already tried: git commit --allow-empty -m "Initial commit"

For problems specific to Sledbot, see Troubleshooting Sledbot or contact support.

Common questions

Is an empty commit bad practice?

No. It is a common way to give a new repo a base commit. If you prefer, commit a README or .gitignore as the first commit instead.

Why does git log say something different from git rev-parse?

Both fail for the same reason but word it differently. git log says the current branch does not have any commits yet. git rev-parse HEAD reports the ambiguous argument error.

Does this affect an existing repo with history?

Not normally. A repo with commits has a HEAD that resolves. If you see the error there, you are probably in a different or freshly created folder, or in a copy that has no commits.

Does Sledbot create the first commit for me?

Only in New Project, when Make an empty first commit or Commit the files is on. See Start an agent on a task and Getting started with Sledbot for the normal flow.

Every app.
One purchase.