$ git push -u origin main после этой комманды выдает
error: src refspec main does not match any
error: failed to push some refs to ‘https://github.com/…’
при этом, если я сделаю $ git push -u origin master, то создается новая ветка и туда отправляются нужные файлы, правда как с ней взаимодействовать — непонятно, все выводится списком
при этом я пытаюсь принять пуш, но ничего не происходит
а еще если попытаться опять что-нибудь закоммитить $ git commit -m «#1»
то получается:
On branch master
nothing to commit, working tree clean
то есть локально у меня главная ветка master? а на гите main, из-за этого не может быть проблем?
-
Вопрос задан23 июл. 2022
-
1338 просмотров
Команда git push -u origin main
делает отправку локальной ветки main
во внешний репозиторий origin
, но ветки main
не существует, о чем вам и сообщили в ошибке.
Вам нужно либо переименовать master
в main
:
git branch -M main
Либо так и написать, что вы хотите master
отправить во внешний main
git push -u origin master:main
Но судя по скрину, у вас репозиторий не пустой. Вы уже создали там ветку с первоначальным коммитом. Поэтому вы не сможете просто так туда сделать push, так как ваши ветки не имеют общей истории. Это РАЗНЫЕ деревья. В таких случаях можно просо пересадить локальную ветку на вершину внешней через rebase. Либо создать ПУСТОЙ репо, как вы и сделали.
Пригласить эксперта
*** нет цензурных слов)
в моем репозитории на гите лежал файл readme.md
даже если я его пулил на локальный репозиторий, это не помогало
в итоге создал все заново без всяких доп файлов и нормально запушилось
+ добавил git branch -M main
-
Показать ещё
Загружается…
13 февр. 2023, в 17:43
3000 руб./за проект
13 февр. 2023, в 16:58
25000 руб./за проект
13 февр. 2023, в 16:52
5000 руб./за проект
Минуточку внимания
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
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
This post talks about how to fix a git error.
error: src refspec master does not match any
error: failed to push some refs to ‘url.git’.
Possible causes for this error for the below use cases
- Create and commit changes to the remote repository
- Push the existing repository from the command line
Here are the steps and commands for creating and cloning and committing the repository
- git init
- git add README.md
- git commit -m “Initial Changes”.
- git remote add origin https://github.com/intkiran/angular-mock-api-json.git
- git push -u origin master
error: src refspec master does not match any error: failed to push some refs to ‘url.git’
There are two use cases success
and error
flow.
Let’s see how we can reproduce these error
use cases.
These are the not correct way of adding commits and pushing changes but given an example use case how we can reproduce this error?
-
I have a local project created
angular-crud-mock-api
in theb:\githubwork
directory. -
Create an empty repository in github.com my repository url.
https://github.com/intkiran/angular-mock-api-json.git
- Now want to commit angular-curd-mock-api code changes into the Repository url
existing local application created `angular-crud-mock-api which is not synced with the GitHub repository. - Let’s see how to add these changes to the remote repository
:githubworkangular-crud-mock-api>git remote add origin https://github.com/intkiran/angular-mock-api-json.git
- Issue git push command and throws an error
B:githubworkangular-crud-mock-api>git push -u origin master
error: src refspec master does not match any
error: failed to push some refs to 'https://github.com/intkiran/angular-mock-api-json.git'
That means, we have to add the first files or directory before pushing changes.
- Add the files and directories using the below command
git add .
B:githubworkangular-crud-mock-api>git add .
warning: LF will be replaced by CRLF in angular-crud-mock-api/.browserslistrc.
The file will have its original line endings in your working directory.
It adds the changes to the local repository in git.
Now, Let’s try to push changes to the remote repository using the git push
command.
- Next, push changes using the
git push
command.
B:githubworkangular-crud-mock-api>git push -u origin master
error: src refspec master does not match any
error: failed to push some refs to 'https://github.com/intkiran/angular-mock-api-json.git'
This error throws an error and you need to use the commit command before pushing the Command.
- commit changes
Here are the committed changes to the local repository.
B:githubworkangular-crud-mock-api>git commit -m "Initial changes"
[master (root-commit) 96c6c0c] Initial changes
29 files changed, 30724 insertions(+)
How to add add,commit push Success Flow in Github
Let’s see how we can reproduce these success
use cases.
Here is a sequence of commands you need to run to avoid the error.
git remote add origin https://github.com/intkiran/angular-mock-api-json.git
git add .
git commit -m "Initial changes".
git push -u origin master
Here is the output of push changes
B:githubworkangular-crud-mock-api>git push -u origin master
Enumerating objects: 38, done.
Counting objects: 100% (38/38), done.
Delta compression using up to 4 threads
Compressing objects: 100% (34/34), done.
Writing objects: 100% (38/38), 260.09 KiB | 5.20 MiB/s, done.
Total 38 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (1/1), done.
To https://github.com/intkiran/angular-mock-api-json.git
* [new branch] master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.
fix git error:src refspec origin does not match any
You have to carefully check the below things to avoid this error, if you create new repo or push an existing repository,
-
You forgot to add the files before pushing changes to the master or branch
-
Missing or skipping the
git add .
orgit commit
command throws an error
Here are steps for adding the files or directories
- git commit message enclosed in
double quotes
instead ofsingle quotes
Valid
git commit -m "initial changes"
Invalid
git commit -m 'initial commit'
- Please check the branch name with the push command
Usually, we will push changes using the below command.
git push -U origin `branchame`
push command push changes from the local repo to the remote repository branchname
Please make sure that branchname
exists.
‘master ‘ is the default branch.
Here is a correct command
git push -U origin master
Possible reasons
- Branch name not found
- Branch name spelling mistake or case insensitive
How to create a new repo to avoid this error in Git
here is a list of commands to avoid this error
git init
git add .
git commit -m 'message'
git push -u origin master
Conclusion
In this tutorial, Learn how to fix the git error:src refspec origin does not match any while working with git repositories.
in Git
November 29th, 2022
Views
1. Introduction
In this example, we shall explain to you in detail what an “error: src refspec main does not match any” in “git” is and how you can deal with such errors if you encounter them in the future.
2. Error Description
This error occurs when you try to push code from a local repository to a remote repository while using the "git push origin main"
command in git command line
using git bash
and it happens that there is no main branch present hence an error.
3. Recreating the Error
There are several things that can trigger an "src refspec error main does not match any"
error. The illustration below will show you how to produce this error.
Let’s assume you cloned a new repository where the default branch is master and there is no main branch. When you type the command: "git push origin main"
, it displays the "refspec main"
error like this:
4. Dealing with refspec errors
Now that you are aware of the "refspec error"
, let’s explain how to deal with such errors in git
. Whenever you encounter such errors don’t panic just follow these procedures like this:
Display the remote branches connected to your local branch on your computer using the "git branch -b"
command like this:
git branch -b
#results
# origin/master
From the above result, it is seen that we have only the master branch
available in our remote repository
and no main branch
hence that explains why we had the "src refspec main does not match any"
error.
In order for us to create a branch
called main
where we are going to migrate eventually to, we can either create branch
directly on the Github website
or we use the git terminal
and type the command like this:
After creating the "main branch"
we are going to type the command "git push origin main"
and it won’t display an error anymore proving that we have resolved the error.
5. Conclusion
When next you encounter an "error: src refspec main does not match any"
, just know that the main branch
does not exist in your remote repository
and hence try to create one.
Table of Contents
Show
As you may be aware, Git is an open and accessible version control system that enables you to manage small to big projects efficiently.
However, while making modifications to the file locally or on the server, you may see problems: src refspec master does not match any.
If you’re receiving this error, you’ve come to the right place. Throughout this article, you will encounter various scenarios in which you will experience this type of error and how to resolve it using the provided solution.
Related: Your IP Has Been Temporarily Blocked | How to Unblock My IP Address
What Does src refspec Master Does not Match Any
Mean in Git?
When attempting to initiate a push from a local repository to a master repository, you may receive the following error:
git push origin master
This error can occur for a variety of reasons.
The absence of the main branch most likely causes this problem.
Perhaps you cloned a new repository, and the default branch is main; thus, when you try to push for it, there is no main branch.
Using the git branch -b command, you may see which remote branches are linked to a local repository:
git branch -b
# results
# origin/main
# origin/feat/authentication
# origin/other branches ...
According to the results above, there is no master repository (origin/master). When you attempt to push to that repository, you will receive the “respec error.”
This finding likewise holds for any other branches that do not exist. Assume I make changes and push to a remote hello branch that does not exist:
Related: How to Play Roblox on a School Computer | 2023
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
When Does Git Throw an Error: src refspec Master Does not Match Any?
There are different scenarios when Git throws an error: src refspec master does not match any.
Scenario 1: Pushing the Empty Directory
The first case for getting this error: src refspec master does not match any.
Assume you’ve set up a Git repository and included all of the files from your local branch, but instead of committing them, 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 .
Related: Unblocker for School: 9 Methods to Unblock Websites for School, Home & Work
If you git push after adding the files from the local branch, you will receive the following error: src refspec master does not match any. Error: certain references were not pushed to master.
git push -u origin master error: src refspec master does not match any.
Solution
The answer to this problem is as simple as creating a file within that directory before committing and pushing it to the remote server.
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’re using GitHub, the master branch has been replaced with the main branch. As a result, the local branch and remote branch ref will disagree in these instances, and when you try to push the modifications, Git will produce an error since the remote branch itself is not present.
# To get all the ref git show-ref # replace with your branch name according to ref git push origin HEAD:<branch>
Solution
Check to see what refs you have, and then make a Git push to the appropriate remote branch.
Related: What Does 5K Subscribers Mean on Snapchat
Scenario 3: Mismatch in Local and Remote Branch
Even a mistake in the branch name while pushing the change to the remote branch will usually result in a refspec issue.
Solution
Validate and verify that you used the correct branch name when posting the code to the remote branch.
Scenario 4: Committing and Pushing Empty Directory in Git
Specific versions of Git, such as GitHub and Bitbucket, do not monitor empty directories; thus, if a directory is empty and you try to commit and push, an error will occur: src refspec master does not match any.
Solution
Before pushing a file to a remote branch, add it to your directory.
Conclusion
The “source refspec master does not match any” error message. This error can arise for a variety of reasons.
The absence of the master branch most likely causes this problem. Perhaps you cloned a new repository, and the default branch is main; thus, when you try to push for it, there is no master branch.
Suppose you forget to include the files you’ve altered to a commit and try to push those changes to a remote repository before making the first commit in your repository. In that case, you’ll get the “source refspec master does not match any” issue.
These conditions might result in the git error “error: source refspec master does not match any.”This error will be resolved if you carefully apply the remedy.
Frequently Asked Questions
The “src refspec master does not match any” error occurs if you have forgotten to add the files you have changed to a commit and try to push those changes to a remote repository before you make the first commit in your repository.
Why is git Push Origin Main Not Working?
If git push origin master is not working, all you need to do is edit that file with your favorite editor and change the URL = setting to your new location.
Assuming the new repository is set up correctly, and your URL is correct, you’ll easily be able to push and pull to and from your new remote location.
How do I Fix Error SRC Refspec Main Does Not Match Any?
The solution to this error is to either create a local and remote master branch to which you can push the commit or push the commit to an existing branch – maybe the main.
These commands will create a master branch locally. And by pushing to the origin master, the master branch will also be created remotely.
How do I Change Local Branch Name?
Git Rename Branch – How to Change a Local Branch Name
- Step 1: Ensure you are in your project’s root directory.
- Step 2: Go to the branch you want to rename.
- Step 3: Use the -m flag to change the name of the branch.
- Step 1: Make sure you are in the master/main branch.
- Step 2: Use the -m flag to rename the branch
FAQs
What does SRC Refspec master does not match any mean?
The “src refspec master does not match any” error occurs if you have forgotten to add the files you have changed to a commit and try to push those changes to a remote repository before you make the first commit in your repository.
Why is git push origin main not working?
If git push origin master is not working, all you need to do is edit that file with your favorite editor and change the URL = setting to your new location.
Assuming the new repository is set up correctly and your URL is correct, you’ll easily be able to push and pull to and from your new remote location.
How do I fix error SRC Refspec main does not match any?
The solution to this error is to either create a local and remote master branch to which you can push the commit or push the commit to an existing branch – maybe the main.
These commands will create a master branch locally. And by pushing to the origin master, the master branch will also be created remotely.
How do I change local branch name?
Git Rename Branch – How to Change a Local Branch Name
- Step 1: Ensure you are in your project’s root directory.
- Step 2: Go to the branch you want to rename.
- Step 3: Use the -m flag to change the name of the branch.
- Step 1: Make sure you are in the master/main branch.
- Step 2: Use the -m flag to rename the branch.
References
- itsmycode.com – Git error: src refspec master does not match any.
- datasciencelearner.com – error src refspec master does not match any: Git Error ( Solved )
- freecodecamp.org –
Recommendations
- Number of Days, Hours, Minutes, and Seconds in each Month of the Year
- Your IP Has Been Temporarily Blocked | How to Unblock My IP Address
- How to Play Roblox on a School Chromebook | 2022
- Who Buys Broken tvs Near Me: 15 Best Places to Sell TVs in 2022
- Are Forks Illegal in Canada|The Answer Will Shock You
- 15 Best Backpack Brands For Trips | 2022 Quality Review
- 15 Top Most Popular Cognac Brands in 2022
Describe the bug
When trying to create backup i recieve this error
Relevant errors (if available)
No response
Steps to reproduce
Attempt to push backup
Expected Behavior
No response
Addition context
No response
Operating system
Windows
this should git issue, not related to this plugin, can you push it through cmd?
Yeah, I can. I think it’s issues with something local. Going to wipe and start again
The information transmitted, including attachments, is intended only for the person(s) or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and destroy any copies of this information.
…
________________________________
From: Jason Ho ***@***.***>
Sent: Friday, October 22, 2021 2:19:50 PM
To: denolehov/obsidian-git ***@***.***>
Cc: Callum Gourlay ***@***.***>; Author ***@***.***>
Subject: Re: [denolehov/obsidian-git] [Bug]: Error: Src refspec main does not match any error:failed to push some refs (Issue #126)
this should git issue, not related to this plugin, can you push it through cmd?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub<#126 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/APSTFE2NAZWSQGNIBAGJRILUIFQHNANCNFSM5GMBTEIQ>.
@callumgourlay this error usually appears when you don’t stage files for commit. Running the below bash commands should fix the issue:
I managed to resolve it by adding the .git folders to all the internal folders and after that it worked fine
The information transmitted, including attachments, is intended only for the person(s) or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and destroy any copies of this information.
…
@callumgourlay I am having the same issue, have been having it around the same Oct timeframe but was not very proficient with Git so thought maybe I was doing something wrong. I am able to manually push the files using suggestion that @denolehov provided above but the plugin continues to throw the same error.
Can you explain what you meant by copying all the git folders, are you copy all the contents of the .git folder into each and every nested folder in your vault? appreciate your help.
@denolehov Thank you for the plugin it used to work like a charm for me until this happened.
I managed to sort it by creating a new repository and copying the .git folder from one to another. Other than that I don’t remember much of it as it was a while ago now
The information transmitted, including attachments, is intended only for the person(s) or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and destroy any copies of this information.
…
all of your comments doesn’t work for me. i try to push and see that error : error: src refspec main does not match any