Git “src refspec master does not match any” Error – How To Fix

Error “src refspec master does not match any”

This article discusses the error “src refspec master does not match any”, why this error occurs, what it means and how it can be resolved.

Causes of “src refspec master does not match any” error

Suppose we have a project folder: Project1. First, open the terminal and move into that folder.

cd Project1 

Now, we will initialize a Git Repository:

git init

We also create a python file in folder Project1. It’s named

def welcome(city: str):
	print(f“Welcome to {city}”)

if __name__ ==  ‘__main__’:

Ok, now we have this file in our repository. Let’s create a link from the local repository (the version stored on your computer) to the remote repository (the version stored on GitHub) so that changes inside the project are easily updated.

git remote add origin
git add .
git push -u origin master

After running the push command, you will get the error message


error: src refspec master does not match an

This error occurs because you forgot to commit before executing the push command, or maybe the master branch doesn’t exist.

To be clear, you can check the branches yourself by running the git branch command.

Solutions to this problem

To avoid errors, make sure you initiate a commit before pushing it.

git commit -m "Code optimization commit"

Then check the branch name to see if there is a master branch. Creating a master branch in local and remote repositories would be best. To make a remote master branch, you can access to GitHub website, or you can use these commands above:

git checkout -b master
git push origin master

Another tip is that instead of using the master branch, you can utilize the current default branch as the main branch.


So I helped you fix the “src refspec master does not match any” error. To avoid errors, pay attention to the order in which the steps are executed and the branch name.

Maybe you are interested:

Leave a Reply

Your email address will not be published. Required fields are marked *