How to Fix ‘Src Refspec <Branch> Does Not Match Any’ When Pushing Commits in Git

Better Stack Team
Updated on June 24, 2024

The error message "src refspec does not match any" typically occurs when you try to push a branch that doesn't exist locally or hasn't been created yet. Here's how you can fix it:

Ensure the Branch Exists Locally

First, ensure that the branch you're trying to push exists locally. You can list all local branches using:

 
git branch

If the branch doesn't exist locally, you need to create it first. You can create a new branch and switch to it using:

 
git checkout -b <branch-name>

Replace <branch-name> with the name of the branch you want to create.

Check if You're Pushing to the Correct Remote

Verify that you're pushing to the correct remote repository. You can check the configured remotes using:

 
git remote -v

Ensure that the remote listed is the one you intend to push to.

Push the Branch

Once you've confirmed that the branch exists locally and you're pushing to the correct remote, you can push the branch using:

 
git push origin <branch-name>

Replace <branch-name> with the name of the branch you want to push.

Note:

  • If the branch exists locally but has no commits, you may encounter this error message. In this case, you can add commits to the branch and then push it.
  • If you're trying to push a branch with a different name to the remote, you need to specify the local branch name explicitly in the git push command.
Got an article suggestion? Let us know
Explore more
Git
Licensed under CC-BY-NC-SA

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.