As you already know git is an open and free version control system that allows you to handle small to large projects in an efficient way. But while making changes to the file locally or server you will generally face errors like the error: src refspec master does not match any. If you are getting this type of error then you have come to the right place. In this entire tutorial, you will different scenarios where you will get this type of error and how you can solve it using the provided solution.
Before going to different scenarios let’s first create a sample project folder and initialize git for it. Make sure you must have git installed in your system.
Execute the following line of code to initialize the git for the project folder.
Create a Sample Folder
Go to the created folder
Initialize the git for the current folder
Different Scenarios when Git throw error :src refspec master does not match any error
Case 1: Pushing the empty directory
The first case for getting this error: src refspec master does not match any is when there is nothing in your directory and you are pushing the changes to the remote branch.
The solution to this error is very simple to try to first create a file inside that directory and then commit and push to the remote server.
Case 2: Push to the master branch before committing
The second case when this error came is when you are pushing the changes directory to the master branch.
The solution for this case is that you should commit all changes and then push to the master branch. You will not get any errors.
Case 3: No branch in remote exists and getting the error src refspec master does not match any error
The third case for getting this error is when there is no branch in the remote with the same name in your local host. For example, if I push the changes to the master branch then I will get this error. Because there is no master branch in the remote.
The solution of the case is to first find all the references to the branches and then push to that remote branch. To get the references you have to use
You can see I was pushing to the master branch but in the remote the branch name was main. So to remove the error src refspec master does not match any error, push changes to the main branch.
Case 4: Not matching the name of local and remote branch
If your local branch name is different from the remote branch name then you will get this type of error. For example, my remote branch name is main and but I am trying to push the changes to main branch.
The solution for this case is very simple. Check the name of the local and remote branches before pushing the changes. You will not see any errors.
These are the different scenarios when you can get git error “error: src refspec master does not match any“. If you carefully apply the solution then this error will be solved. The most common error comes from case 4. I hope you have liked this tutorial. If you still facing this error then you can contact us for more help.
Join our list
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.