Your Code. Your Rules.

src refspec Does Not Match

error: src refspec main does not match any - the first push of an empty repository, or a branch with another name.

src refspec Does Not Match Any

Symptom

error: src refspec main does not match any
error: failed to push some refs to 'https://<INSTANCE>.git.eu/<USERNAME>/<REPO>.git'

Cause

Your clone has no local branch with the name you pushed:

  • the repository has no commit yet (a new or freshly cloned empty repository);
  • the local branch has another name, for example master instead of main.

Diagnose

git branch --show-current
git log --oneline -1

The first command prints the local branch name. does not have any commits yet from the second means there is nothing to push.

Fix

Option A - Commit first (recommended)

git add .
git commit -m "First commit"
git push -u origin main

Option B - Push the branch you have

Push the current branch under its own name:

git push -u origin HEAD

Or rename it to main first, then push:

git branch -M main
git push -u origin main

Verify

git ls-remote origin

It lists refs/heads/main.

Prevent

  • Commit before the first push.
  • Use the branch name the repository page shows.

Related