Maybe you just need to commit. I ran into this when I did:

mkdir repo && cd repo
git init
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 main

Success!

Answer from baisong on Stack Overflow
🌐
Reddit
reddit.com › r/git › error while using git push error: src refspec not match any
r/git on Reddit: Error while using git push error: src refspec not match any
March 19, 2024 -

I want to push the changes in my local repo to remote repo in a certain branch.

>git push -f https://gitlab.xyz.com/<path> Upgrade-qa

error: src refspec Upgrade-qa does not match any

error: failed to push some refs to 'https://gitlab.xyz.com/<path>.git'

Earlier to this I performed the set of commands like

>git init

>git remote add origin <remote repo path>

>git add .

>git commit -m "QA Upgrade"

> git push -f https://gitlab.xyz.com/<path> Upgrade-qa

While I searched on the same issue , I found that people would suggest to use 'git pull' with rebase option.

I am new to git and in my local repository I have made the changes. All the changes I want to push it to remote repo in a certain branch. I am afraid if I would use 'git pull' then all the remote repo code would be merged to my local repo then how I would be able to merge my local changes to remote.

I still feel unsafe because if I use git pull my local codebase in the local repo would be subjected to change but I wish to continue working on my local repo from the same instant again.

Discussions

Error: src refspec main does not match any
Maybe your local branch is named different. Can you share the command you're running and the full error? As well as the output of git branch -v More on reddit.com
🌐 r/CodingHelp
2
1
July 9, 2022
I get "refspec main does not match any" on setup
But when Im following all the scripts i get "refspec main does not match any. " when the script is trying to setup git actions. After i set the FLY_API_TOKEN. error: src refspec main does not match any. More on github.com
🌐 github.com
3
June 19, 2023
How to fix “error: src refspec main does not match any”?
I’m trying to push my code to GitHub but getting error: src refspec main does not match any. I’m not sure if it’s a branch issue or something else. Has anyone solved this before? More on forum.getassist.net
🌐 forum.getassist.net
3
0
December 2, 2025
Src refspec master does not match any
Dear GitLab community, out of sudden my deployment jobs are failing with message “src refspec master does not match any”. I did some research and I have absolutely no idea why. However, when I compare current deployment job log with previous one I see this difference: Current (Not working): ... More on forum.gitlab.com
🌐 forum.gitlab.com
17
1
March 16, 2019
🌐
Sentry
sentry.io › sentry answers › git › git src refspec master does not match any error message
Git src refspec master does not match any error message | Sentry
March 15, 2023 - To resolve the issue, first check the push command. For example, if you’ve changed the primary branch name from master to main, running git push origin master will produce this error message, and you should run git push origin main instead.
🌐
Medium
medium.com › bugs-that-bite › error-src-refspec-master-does-not-match-any-71b0e0750e38
error: src refspec master does not match any. | by Teri Radichel | Bugs That Bite | Medium
February 18, 2024 - error: src refspec master does not match any. Similar to a prior git error when trying to push files but not exactly ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ⚙️ Check out my series …
🌐
freeCodeCamp
freecodecamp.org › news › error-src-refspec-master-does-not-match-any-how-to-fix-in-git
Error: src refspec master does not match any – How to Fix in Git
August 1, 2022 - 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.
🌐
Coderanch
coderanch.com › t › 742117 › build-tools › error-src-refspec-main-match
error: src refspec main does not match any (Other Build Tools forum at Coderanch)
The real solution is to ask yourself why you're trying to add these files to your source repository in the first place. You should only add hand-coded source files; not binaries, generated source files or tools. What does your .gitignore file look like? You should set it up so it ignores everything ...
Find elsewhere
🌐
Atlassian Support
support.atlassian.com › bitbucket-data-center › kb › error-when-pushing-to-repository-src-refspec-master-does-not-match-any
Error when pushing to repository: Src refspec master does not match any | Bitbucket Data Center | Atlassian Support
April 15, 2025 - If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options. ... When pushing a new repository to the Bitbucket Server, the following error is returned from the Git client: git push -u origin master error: src refspec master does not match any.
🌐
Baeldung
baeldung.com › home › git › the problem with ‘src refspec does not match any’
The Problem With ‘src refspec does not match any’ | Baeldung on Ops
February 6, 2024 - Many of us have seen the refspec error message at least once within the console. This error occurs on pushing to a remote repository. Let’s try to understand what this line exactly means: ... Simply put, this error message tells us that we don’t have a branch we want to push, which is the main reason for this error.
🌐
GitHub
github.com › epicweb-dev › epic-stack › issues › 199
I get "refspec main does not match any" on setup · Issue #199 · epicweb-dev/epic-stack
June 19, 2023 - git push -u origin main is not working when im doing it in the terminal, I need to run git branch -M main first. Then it works.
Author   epicweb-dev
🌐
GetAssist
forum.getassist.net › how-to guides
How to fix “error: src refspec main does not match any”? | GetAssist Forum
December 2, 2025 - The Git error “error: src refspec main does not match any” happens when the main branch doesn’t exist or no commits are present. Check your branches with git branch, create or switch to main, add files, and make an initial commit.
🌐
GitLab
forum.gitlab.com › gitlab ci/cd
Src refspec master does not match any - GitLab CI/CD - GitLab Forum
March 16, 2019 - Dear GitLab community, out of sudden my deployment jobs are failing with message “src refspec master does not match any”. I did some research and I have absolutely no idea why. However, when I compare current deployment job log with previous one I see this difference: Current (Not working): Running on runner-72989761-project-4417089-concurrent-0 via runner-72989761-srm-1552747221-b30389b8…
🌐
Atlassian Community
community.atlassian.com › q&a › bitbucket › questions › error: src refspec master does not match any
error: src refspec master does not match any
September 25, 2024 - Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type. ... Those new to the Atlassian Community have posted less than three times. Give them a warm welcome! ... I have a lot of repo on bitbucket and never had an issue but today, when trying to create a new one, i seem to cannnot set a default master branch, i set it in the repo creation but when i try to push my local code to the repo i get the following: git push origin master error: src refspec master does not match any error: failed to push some refs to 'https://bitbucket.org/******/frontend.git'
🌐
Atlassian Community
community.atlassian.com › products › bitbucket › questions › splitting repository fails: src refspec master does not match any
Splitting Repository Fails: src refspec master does not match any
May 20, 2019 - Splitting Repository Fails: src refspec master does not match any · Tom Purcell May 20, 2019 edited · Hello · I'm following the directions at : https://confluence.atlassian.com/bitbucket/split-a-repository-in-two-313464964.html · When I get to the part where you push origin to mater I get: ~/test/split/ansible [develop] $ git push origin master error: src refspec master does not match any.
🌐
DataOps Redefined!!!
thedataops.org › home › resolving git push error: src refspec master does not match
Resolving Git Push Error: src refspec master does not match - DataOps Redefined!!!
March 7, 2024 - One such error is “src refspec master does not match any,” which indicates that Git couldn’t find the specified branch to push. This error typically occurs when you haven’t committed any changes to your local repository or when the branch you’re trying to push doesn’t exist locally.
🌐
Qiita
qiita.com › git
初回git push 時の「src refspec master does not match any」解決法 #Git - Qiita
January 18, 2022 - 1行目の「error: src refspec master does not match any」で調べてみる。 ... 以前までは「master」ブランチが自動で作成されていたのですが、2020/10以降、新規にレポジトリを作成すると、「main」ブランチが作成されるようだ。
🌐
Mazer.dev
mazer.dev › en › git › troubleshooting › error-src-refspec-main-does-not-match-any-git
How to fix error: src refspec main does not match any in Git - Mazer.dev
February 22, 2023 - The most common cause for this error: src refspec main does not match any occurs is when there are missing files in the project track, ie missing execute the git commit command. You can even check on Github by clicking on commits if there are ...
🌐
Velog
velog.io › @nasubeeni › Git깃허브-error-src-refspec-main-does-not-match-any
[Git/깃허브] error: src refspec main does not match any
November 24, 2023 - 로컬 Repo → Main Repo로 push하려 할 때 이런 에러를 마주할 것이다. ... This error can occur for different reasons. The most likely reason this error will occur is that the main branch does not exist.
🌐
GitHub
github.com › jesseduffield › lazygit › discussions › 3121
src refspec matches more than one · jesseduffield/lazygit · Discussion #3121
November 21, 2023 - Unset the upstream via the menu, rename the branch to main and push it to origin/main. Tried it now and it works, and requires no intervention from our side. The tag named refs/heads/master is not something I have come across, so I take it this ...
Author   jesseduffield