I have tried to follow the solutions suggested in this post but it didnt work and I am still getting: src refspec master does not match any.
Here is what I did:
Followed this solution
// adding the file I created
$ git add .
$ git commit -m 'initial commit'
$ git push origin master
error: src refspec master does not match any.
When doing:
$ git push origin HEAD:master
b40ffdf..a0d1423 HEAD -> master // looks promising
// adding a remote
$ git remote add devstage -f <another git>
$ git merge devstage/master -s recursive -X ours
$ git push -u devstage master
error: src refspec master does not match any.
More information:
$ git branch
* origin
$ git show-ref
refs/heads/origin
refs/remotes/devstage/master
refs/remotes/origin/HEAD
refs/remotes/origin/devstage
refs/remotes/origin/master
refs/remotes/origin/origin
So I am definitely missing refs/heads/master but dont know how to create it.
Thanks
asked Jan 21, 2014 at 17:13
special0nespecial0ne
6,03317 gold badges66 silver badges107 bronze badges
4
This should help you
git init
git add .
git commit -m 'Initial Commit'
git push -u origin master
answered Nov 26, 2015 at 5:42
3
From git branch
it appears that somehow your local branch name is «origin».
You can rename the branch with -mv
flag, like this:
git branch -mv origin master
After this git branch
should show master
Just to make sure the name is indeed the only thing that went astray, you can run git log
and look at the last few commits — and compare them to the last few commits on bitbucket website.
answered Jan 21, 2014 at 19:29
apprenticeDevapprenticeDev
8,0293 gold badges22 silver badges25 bronze badges
5
Try to do :
git push origin HEAD:master
answered Nov 29, 2017 at 14:53
1
i have same problem, to solve it, follow these steps
git init
git add .
git commit -m 'message'
git push -u origin master
after this, if you still having that error, follow these steps again
git add .
git commit -m 'message'
git push -u origin master
that worked for me and Hope it will help anyone
answered Mar 4, 2017 at 16:51
2
Try following command:
git push origin HEAD:master
Git threw the below error when I tried simply git push
. So clearly this is because Git matches the local and remote branch while pushing commits. This is the push.default
behavior, you can find out more details here.
fatal: The upstream branch of your current branch does not match
the name of your current branch. To push to the upstream branch
on the remote, use
git push origin HEAD:<Branch_Name>
To push to the branch of the same name on the remote, use
git push origin <Branch_Name>
To choose either option permanently, see push.default in 'git help config'.
answered Apr 10, 2018 at 7:03
SaikatSaikat
13.7k20 gold badges102 silver badges122 bronze badges
0
By just adding an empty commit will fix issue by using
$ git commit -m "empty commit" --allow-empty
$ git push
above. make empty commit without edit then push
answered Jan 12, 2019 at 10:40
Bourbia BrahimBourbia Brahim
14.3k4 gold badges38 silver badges51 bronze badges
0
I was having the SAME ERROR AGAIN AND AGAIN.
I added files in local repository and Trying the command
«git push origin master»
Showed Same Error
ALL I WAS MISSING I DID NOT COMMIT .
» git commit -m ‘message’ «
After Runnig this it worked
answered Mar 2, 2018 at 17:28
2
The clue is in the error
error: src refspec master does not match any.
Github’s recently changed its default branch to main.
Take a look here
On your local setup you could rename your local branch as shown below
git branch -m master main
or you could push from your master to main
git push origin master:main
answered Oct 23, 2021 at 20:17
pcodexpcodex
1,78215 silver badges16 bronze badges
Run the command git show-ref
, the result refs/heads/YOURBRANCHNAME
If your branch is not there, then you need to switch the branch by
git checkout -b "YOURBRANCHNAME"
git show-ref
, will now show your branch reference.
Now you can do the operations on your branch.
answered Jul 6, 2017 at 7:08
SonuSonu
7028 silver badges7 bronze badges
0
In my case the error was caused because I was typing
git push origin master
while I was on the develop branch
try:
git push origin branchname
Hope this helps somebody
answered Jun 17, 2017 at 10:47
The error demo:
007@WIN10-711082301 MINGW64 /d/1 (dev)
$ git add --all
007@WIN10-711082301 MINGW64 /d/1 (dev)
$ git status
On branch dev
Initial commit
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: index.html
new file: photo.jpg
new file: style.css
007@WIN10-711082301 MINGW64 /d/1 (dev)
$ git push origin dev
error: src refspec dev does not match any.
error: failed to push some refs to 'git@github.com:yourRepo.git'
You maybe not to do $ git commit -m "discription"
.
Solution:
007@WIN10-711082301 MINGW64 /d/1 (dev)
$ git commit -m "discription"
[dev (root-commit) 0950617] discription
3 files changed, 148 insertions(+)
create mode 100644 index.html
create mode 100644 photo.jpg
create mode 100644 style.css
007@WIN10-711082301 MINGW64 /d/1 (dev)
$ git push origin dev
To git@github.com:Tom007Cheung/Rookie-s-Resume.git
! [rejected] dev -> dev (fetch first)
error: failed to push some refs to 'git@github.com:yourRepo.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
answered Dec 17, 2017 at 15:36
MaiMai
1353 silver badges15 bronze badges
1
This is happend to me once I forgot to add files. So I got the same error. All you need to do is add your files.
- Add your files =>
git add .
or the name of the files you want to add. you supposed to init first your repo withgit init
. - Commit your changes =>
git commit -m 'Initial Commit'
. - Now push your changes =>
git push -u origin master
answered Feb 3, 2020 at 18:28
DINA TAKLITDINA TAKLIT
6,7459 gold badges69 silver badges73 bronze badges
this error occurs when you clone a repo from one branch and you trying to push changes to another branch just try to make sure that you are in the same branch compared to the branch that you are trying to push if it isnot the same just clone your repo again from that specific branch by using git clone -b <branchname> <remote-repo-url>
then retry to push changes
answered Sep 12, 2021 at 12:38
Ensure that if you are pushing the master branch then ensure that you’re currently in the master branch if not checkout to the master branch and now push your commits. To list all current branches in your working directory use :
git branch
Your currently working branch should have an asterisk at the beginning for instance if am working on my a devstage branch it would appears as shown below :
*devstage
master
In this case, push the commits in the devstage branch first then perform a git pull request if you want to merge the two branches that is the master and the devstage.
answered May 31, 2021 at 20:02
stanley mbotestanley mbote
8901 gold badge7 silver badges17 bronze badges
Check that you call the git commands from the desired directory (where the files are placed).
answered Mar 19, 2017 at 12:42
NoamGNoamG
1379 bronze badges
This error can typically occur when you have a typo in the branch name.
For example you’re on the branch adminstration
and you want to invoke:
git push origin administration
.
Notice that you’re on the branch without second i
letter: admin(i)stration
, that’s why git prevents you from pushing to a different branch!
answered Oct 6, 2017 at 8:42
Setup username and password in the git config
In terminal, type
vi .git/config
edit url with
url = https://username:password@github.com/username/repo.git
type :wq
to save
answered Oct 14, 2017 at 13:55
Prashanth SamsPrashanth Sams
19.2k20 gold badges101 silver badges125 bronze badges
Only because your local branch does not math the one in your remote repository.
git push origin HEAD:master
Enable you to ignore the conflict and upload your commit anyway.
answered Jan 19, 2018 at 1:44
0
I had the same problem recently. but now resolved this issue. Because, Now GitHub changed master to main. It works well for me. Use git push origin main
instead of git push origin master
. Hopefully, It will work.
answered Sep 21, 2021 at 15:15
Vintage CoderVintage Coder
4311 gold badge6 silver badges9 bronze badges
For me, the fix appears to be «git .» (stages all current files). Apparently this is required after a git init?
I followed it by «get reset» (unstages all files) and proceeded with the exact same commands to stage only a few files, which then pushed successfully.
git .
git reset
answered Jun 17, 2017 at 17:01
JohnP2JohnP2
1,87919 silver badges17 bronze badges
It happened to me and I discovered that github was trying to verify my account. So you need these 2 commands:
git config --global user.email <your github email>
git config --global user.name <your github username>
answered Nov 30, 2018 at 15:00
jessjess
237 bronze badges
FWIW, ran into same error, but believe it came about due to the following sequence of events:
- Remote Git repo was created with
master
branch. - Local clone was then created.
- Remote Git repo was then modified to include a
dev
branch, which was defined as the default branch, in conjunction with permissions added to themaster
branch preventing changes without a pull request. - Code updates occurred in the local clone, ready to be pushed to the remote repo.
Then, when attempting to push changes from the local to the remote, received error «src refspec master does not match any», or when attempting to push to dev
, «src refspec dev does not match any».
Because changes were pending in the local clone, I did not want to blast it and refresh.
So, fixed the issue by renaming the local branch to dev
…
$ git branch -m dev
…followed by the normal push of git push origin dev
, which worked this time without throwing the aforementioned error.
answered Sep 4, 2019 at 18:37
TrentiumTrentium
3,3792 gold badges12 silver badges19 bronze badges
This error is also caused due to an unmatched local branch name.
Make sure that you are giving correct local branch name (check spelling and case sensitivity)
I had the same error because my local branch name was «validated» and was trying to push the changes using git push -f origin validate
, updated that to git push -f origin validated
worked.
Hope this helps.
answered May 2, 2020 at 15:43
RupeshRupesh
8201 gold badge12 silver badges26 bronze badges
I also faced the same error.
In my case below is the scenario.
I have master branch which set as origin.
Other side I have release branch «Release_branch».
I have to fork my feature branch(i.efeature/testBranch) from Release branch.
Below are the steps I did.
$ git checkout Release_branch
$ git pull
$ git checkout feature/testBranch
$ git commit -m "SOME_MESSAGE"
$ git push -u origin feature/testBranch
answered May 4, 2021 at 11:16
rahulnikharerahulnikhare
1,3521 gold badge17 silver badges25 bronze badges
I had this error (error: src refspec master does not match any
) with a new repository, when trying git push origin master
, because GitHub changed the default name of the master branch to main
.
So, git push origin main
is working for me.
answered May 15, 2021 at 10:46
For a new repository, the method works for me:
-
Remote the files related with git
rm -rf .git
-
Do the commit again
git add . && git commit -m "your commit"
-
Add the git URL and try to push again
git remote add origin <your git URL>
-
And then try to push again
git push -u origin master -f
-
Success!
Since it’s a new repository, so it doesn’t matter for me to remove the git and add it again.
answered Nov 24, 2018 at 22:41
backslash112backslash112
2,0551 gold badge23 silver badges29 bronze badges
I had already committed the changes and added all the files, had the same origin as remote, still kept getting that error. My simple solution to this was just:
git push
answered Sep 1, 2020 at 20:54
Vivek SinghVivek Singh
3263 silver badges14 bronze badges
When working with Git, you may come across an error that says «src refspace master does not match any».
Here’s what the error means and how you can solve it.
You may get this error when you try to trigger a push from a local repository to a master repository like this:
git push origin master
This error can occur for different reasons.
The most likely reason this error will occur is that the master
branch does not exist.
Perhaps you cloned a new repository and the default branch is main
, so there’s no master branch when you try to push for it.
You can display the remote branches connected to a local repository using the git branch -b
command like this:
git branch -b
# results
# origin/main
# origin/feat/authentication
# origin/other branches ...
With the above results, you can see that there is no master
repository (origin/master
). So when you try to push to that repository, you will get the «respec error».
This result also applies to any other branch that does not exist. Let’s say, for example, I make changes and push to a remote hello
branch that does not exist:
git add .
git commit -m "new changes"
git push origin hello
This command will produce the following error:
error: src refspec hello does not match any
How to Fix the «src refspec master does not match any» Error
Now you are aware that the master
branch does not exist. The solution to this error is to either create a local and remote master
branch that you can push the commit to or to push the commit to an existing branch – maybe main
.
You can create a remote master
branch on a Git managed website (like GitHub) or you can do that directly from your terminal like this:
git checkout -b master
# add commit
git push origin master
These commands will create a master
branch locally. And by pushing to origin master
, the master
branch will also be created remotely.
But if you do not want to create a master
branch, you can use the existing default branch (which may be main
) instead.
Wrapping up
So if you get the Error: src refspec master does not match any
error when you try to push to master, the most viable reason is that the master
branch does not exist.
Learn to code for free. freeCodeCamp’s open source curriculum has helped more than 40,000 people get jobs as developers. Get started
Я создал новый проект с одним файлом README.md.
И сделал команду
git clone https://github.com/xxxx/xxx.git
git add .
git commit -m "v.01"
git push origin master
Но получаю ошибку
error: src refspec master does not match any
error: failed to push some refs to https://github.com/xxxx/xxx.git
Я вводил
git show-ref
3deeeb53dda70bea0809cff5e4032011ba45ac7d refs/heads/main
27383695f3f76e87254687449d73250254560bbb refs/remotes/origin/HEAD
27383695f3f76e87254687449d73250254560bbb refs/remotes/origin/main
3deeeb53dda70bea0809cff5e4032011ba45ac7d refs/remotes/origin/master
И делал так
Maybe you just need to commit. I ran into this when I did:
mkdir repo && cd repo
git remote add origin /path/to/origin.git
git add .Oops! Never committed!
git push -u origin master
error: src refspec master does not match any.All I had to do was:
git commit -m «initial commit»
git push origin masterSuccess!
Я пытался еще так
git push origin HEAD:master
Но хоть загрузка и произошла но файлы не загрузились в github
Но это не помогло что мне делать как исправить
-
Вопрос заданболее двух лет назад
-
23049 просмотров
Нет ветки master, вот и ругается. Ветка по умолчанию на GitHub теперь называется main.
Команда git branch -vv покажет какие ветки есть локально и с какими внешними ветками связаны.
* main 0e02250 [origin/main] v.01
Надо было делать git push origin main
Либо просто git push т. е. отправить текущую ветку в связанную с ней ветку на внешнем репозитории.
В нашем случае текущая ветка main (помеченная звёздочкой)
отслеживает исходную ветку main в репозитории обозначенном как origin
Что скрывается за сокращением origin покажет команда git remote -v
origin https://github.com/xxx/xxx.git (fetch)
origin https://github.com/xxx/xxx.git (push)
Пригласить эксперта
Ввожу git branch -vv — никакого ответа
git push -u origin main не работает хотя связь с удаленным репозиторием установлена
работает так
Для отправки в удаленный репозиторий
git push origin master:master
-
Показать ещё
Загружается…
04 июн. 2023, в 13:43
2000 руб./за проект
04 июн. 2023, в 13:14
200000 руб./за проект
04 июн. 2023, в 12:23
30000 руб./за проект
Минуточку внимания
Did you try to push changes to master with the following?
$ git push origin master
But received an error that says:
error: src refspec master does not match any
The most common reason for this is that “master” isn’t called “master” anymore. To fix the issue, replace “master” with “main“.
$ git push origin main
Didn’t help?
This is a comprehensive guide to fixing the “error: src refspec master does not match any” -error. You will find easy fixes with explanations as to what’s going wrong.
Reasons for the “src refspec does not match any” -Error
Let’s have a closer look at the problems that might be causing the src refspec error.
1. The “master” Branch Isn’t Called “master”
Recently, Git replaced the name “master” with “main”. This means the default branch of your project is no longer called “master” by default but “main” instead.
Pushing changes to the non-existent “master” branch will cause issues. This is one of the most common explanations as to why you might see “error: src refspec master does not match any” when pushing.
In this case, you can try pushing to “main” instead.
$ git push origin main
If this doesn’t fix the issue, your default branch might have a different name than “main” or “master“.
To figure out what the “master” or “main” is called in your case, run the following:
$ git show-ref
The default branch is one of these references. Pick the one that’s your default branch and push the changes to it.
2. You Forgot to Commit
Another common reason why you might get the “error: src refspec master does not match any” error when pushing in Git is you haven’t made a commit.
For example, let’s start by creating an example repository and try to push it to GitHub:
$ mkdir example $ cd example $ echo "# Just another github repo" >> README.md $ git init $ git add README.md $ git remote add origin https://github.com/user/repo.git $ git push -u origin main
When running these commands, you will see an error:
error: src refspec main does not match any
This happens because you didn’t commit anything to the repository yet. In technical terms, a branch doesn’t exist before there’s at least one commit in the repository.
So make sure you’ve committed the changes before trying to push!
For instance, in the above, we forgot to commit the new README.md file after adding it. To fix this, create a commit and push again:
$ git commit -m "Initial commit"
Summary
The most common reason for the “error: src refspec master does not match any” -error is that you’re trying to push to “master” which these days is called “main“. In other words, you’re trying to push to a branch that doesn’t exist.
Another reason this error might occur is that your branch is empty and doesn’t exist. This can happen if you’ve initialized your repo, and added changes with git add but forgot to commit the changes with git commit. Before the initial commit, the branch doesn’t technically exist, and pushing will fail!
Thanks for reading. Happy coding!
About the Author
-
I’m an entrepreneur and a blogger from Finland. My goal is to make coding and tech easier for you with comprehensive guides and reviews.
Recent Posts
Table of Contents
Hide
- When does git throws error: src refspec master does not match any?
- Scenario 1 – Pushing the changes to master or remote branch
- Solution for error: src refspec master does not match any.
- Scenario 2 – Check if a remote branch exists.
- Scenario 3 – Mismatch in Local and remote branch
- Scenario 4 – Committing and pushing Empty Directory in Git
There are quite a few reasons Git throws an error: src refspec master does not match any. Let us look at each of these cases and the solution to it.
Scenario 1 – Pushing the changes to master or remote branch
Let’s say you have created a git repository and added all the files from your local branch, but before committing the files, you try to push them into the remote branch or master branch.
mkdir repo && cd repo
git remote add origin /path/to/origin.git
git add .
After adding the files from the local branch, if you do git push
, you will get an error: src refspec master does not match any. error: failed to push some refs to master.
git push -u origin master
error: src refspec master does not match any.
Solution for error: src refspec master does not match any.
All you need to perform is git commit with a proper message and then do git push to the remote origin to avoid any errors.
mkdir repo && cd repo
git remote add origin /path/to/origin.git
git add .
git commit -m "initial commit"
git push origin master
Scenario 2 – Check if a remote branch exists.
If you are working with Github, they have replaced the master branch with the main branch. Hence, in these circumstances, the local branch and remote branch ref will differ, and when you try to push the changes, git will throw an error since the remote branch itself is not present.
Solution – First, check what refs you have, and once you find that, make a git push to the specific remote branch.
# To get all the ref
git show-ref
# replace with your branch name according to ref
git push origin HEAD:<branch>
Scenario 3 – Mismatch in Local and remote branch
Generally, even the typo in the branch name while pushing the commit to the remote branch will lead to a refspec error.
Solution – Validate and check if you have given the right branch name while pushing the code to the remote branch.
Scenario 4 – Committing and pushing Empty Directory in Git
A certain version of Git like GitHub, bitbucket does not track the empty directories, so if a directory is empty and you are trying to commit and push, it will lead to an error: src refspec master does not match any.
Solution – Add a file to your directory before pushing it to a remote branch.
Srinivas Ramakrishna is a Solution Architect and has 14+ Years of Experience in the Software Industry. He has published many articles on Medium, Hackernoon, dev.to and solved many problems in StackOverflow. He has core expertise in various technologies such as Microsoft .NET Core, Python, Node.JS, JavaScript, Cloud (Azure), RDBMS (MSSQL), React, Powershell, etc.
Sign Up for Our Newsletters
Subscribe to get notified of the latest articles. We will never spam you. Be a part of our ever-growing community.
By checking this box, you confirm that you have read and are agreeing to our terms of use regarding the storage of the data submitted through this form.