. Advertisement .
..3..
. Advertisement .
..4..
A lot of people new to Git encounter a pop-up with “Error: Src Refspec Master Does Not Match Any” inside. If you don’t know the exact cause of this problem, troubleshooting it can be quite a chore.
That is why we prepared this article, as you can save a lot of time and effort if you know about it in advance.
What is Error: Src Refspec Master Does Not Match Any?
After finishing the Git repository creation process, you will see that your result does not have any commit history. That is why you will need to first create a commit. Most of the time, the workflow to do so is as follows:
– Changing any file
– Add that file to your staging place
– Create the commit
Once you finish the last step, your repository is then ready to be pushed into any remote server of your choosing. However, forgetting this step means that Git will raise Error: Src Refspec Master Does Not Match Any when you try pushing the code.
The reason for it lies in Git’s unsureness of which changes to perform within the remote destination repository.
Example
To help you understand this issue more, we will be making a project in HTML.
mkdir project
cd project
git init
The first two lines serve as the tool to create a directory with the name project and to move our codes into it. git init starts the initialization process for a Git repository by creating a folder with the name .git/. This folder is the house to all of our repository’s configurations.
Then, we create a new file naming index.html with content as follows:
<html></html>
The reason for us using just this one tag is to keep things simple, as we are still in the setting up part. After having this file, we can start with the linking process.
git remote add origin {Your remote repository's hosting address}
git add
git push -u origin master
As the code shows, you can put the address where you are hosting your remote repository. We recommend using GitHub, as it allows an easier time tracking the project with its platform.
Once git remote add origin finishes running, Git has the exact idea of where to put the commit when there is a push to the remote repository. The last thing to do is add the changed file back in with git add and push it to the origin repository with git push.
When you run this code, the error will pop up, as there is no commit creation in both the remote repo and local repo.
Solution
The only thing that you need to do is create a starting commit before attempting to push the code with this sentence:
git commit -m "feat: Create index.html"
Once you add it in, the pushing process will become as smooth as butter. However, if you don’t know about it beforehand, it’s as hard to figure out as the infamous command not found error.
Conclusion
While this error is easy to fix, few people know its cause and solution.
All in all, you just need to keep in mind that Error: Src Refspec Master Does Not Match Any only pops up if you forget about creating a commit in the repo. There is no way that you can successfully push the changed files to any remote repo if you have no commit.
Leave a comment