Message 'src refspec master does not match any' when pushing commits in Git

GitGit CommitGit CloneGit AddGit Refspec

Git Problem Overview


I clone my repository with:

git clone ssh://xxxxx/xx.git 

But after I change some files and add and commit them, I want to push them to the server:

git add xxx.php
git commit -m "TEST"
git push origin master

But the error I get back is:

error: src refspec master does not match any.  
error: failed to push some refs to 'ssh://xxxxx.com/project.git'

Git Solutions


Solution 1 - Git

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 main

Success!

Solution 2 - Git

  1. Try git show-ref to see what refs you have. Is there a refs/heads/master?

> Due to the recent "Replacing master with main in GitHub" action, you may notice that there is a refs/heads/main. As a result, the following command may change from git push origin HEAD:master to git push origin HEAD:main

  1. You can try git push origin HEAD:master as a more local-reference-independent solution. This explicitly states that you want to push the local ref HEAD to the remote ref master (see the git-push refspec documentation).

Solution 3 - Git

I also had a similar error after deleting all files on my local computer, and I have to clean up all files in the repository.

My error message was something like this:

error: src refspec master does not match any.
error: failed to push some refs to 'git@github ... .git'

And it was solved by executing the following commands:

touch README
git add README

git add (all other files)
git commit -m 'reinitialized files'
git push origin master --force  # <- caution, --force can delete others work.

Solution 4 - Git

git push -u origin master
error: src refspec master does not match any.

For that you need to enter the commit message as follows and then push the code:

git commit -m "initial commit"

git push origin master

Successfully pushed to master.

Solution 5 - Git

For me I had to make sure the public key is properly configured on the server (appended in ~/.ssh/authorized_keys) and in GitHub/Bitbucket (added to my SSH keys on GitHub or Bitbucket) - they need to match. Then:

git add --all :/
git commit -am 'message'
git push -u origin master

Solution 6 - Git

I found this happened in a brand new repository after I Git added only a directory.

As soon as I added a file (e.g. a README), Git push worked great.

Solution 7 - Git

Missing or skipping git add . or git commit may cause this error:

git push -u origin master
Username for 'https://github.com': yourusername
Password for 'https://[email protected]': 
error: src refspec master does not match any.
error: failed to push some refs to 'https://github.com/yourusername/foobar.git'

To fix it, reinitialize and follow the proper sequence:

git init
git add .
git commit -m 'message'
git *create remote
git push -u origin master

Solution 8 - Git

To fix it, re-initialize and follow the proper code sequence:

git init
git add .
git commit -m 'message'
git push -u origin master

Solution 9 - Git

This happens too when you are in a specific branch and try to push another branch that does not exist yet, like:

$ git branch
* version-x  # you are in this branch
  version-y

$ git push -u origin master
error: src refspec master does not match any.
error: failed to push some refs to 'origin_address'

Solution 10 - Git

Make sure you've added first, and then commit/ push:

Like:

git init
git add .
git commit -m "message"
git remote add origin "github.com/your_repo.git"
git push -u origin master

Solution 11 - Git

I faced the same problem, and I used --allow-empty:

$ git commit -m "initial commit" --allow-empty
...
$ git push
...
Supplement

One of main reasons of this problem is that some Git servers, such as BitBucket, don't have their master branch initialized when a fresh repository is cloned.

Solution 12 - Git

I faced the same issue some days ago.

If you created a new repository nowadays(2020) then the default branch is main on GitHub.

you can check on GitHub now in your repository branches.

and you can also check branch on the terminal by running the command:

git branch

so that's why you need to run

git push origin main

instead of

git push origin master

Goodluck

Solution 13 - Git

Problem faced

I had the same problem when I was creating a new repository on GitHub and linking it with my react-app in the client computer I have.

I used the following steps:

Commands used before the problem

git init
git commit -m "first commit"
git branch -M main
git remote add origin "_git repository link here_"
git push -u origin main

My mistake

But as you can see my mistake was not using the git add . command I did this mistake because I already had README.md file and GitHub instructs us with basic commands while creating the repository.

My solution

My solution is to use git add . after git init command.

Use the following set of commands in the same order to overcome the problem:

git init
git add .
git commit -m "first commit"
git branch -M main
git remote add origin "_git repository link here_"
git push -u origin main

Solution 14 - Git

Two possibilities :

1- Either you forgot to include the .gitignore file.

Here are all the steps required:

  1. Create an empty Git repository on remote,

  2. On local create the .gitignore file for your project. GitHub gives you a list of examples here

  3. Launch a terminal, and in your project do the following commands:

    git remote add origin YOUR/ORIGIN.git
    
    git add .
    
    git commit -m "initial commit or whatever message for first commit"
    
    git push -u origin master
    

2- Or you are trying to create a new Github project.

Github replaced master with main as the default branch name. To resolve the issue :

  1. On your local project:
    1. remove the .git folder if it exists
    2. recreate a clean repository by launching the following in your project:

in the terminal:

git init

git add .

git commit -m "YOUR FIRST MESSAGE HERE"

git branch -M main

git remote add origin _GIT_LINK_TO_PROJECT_HERE_

git push -u origin main

Solution 15 - Git

For me,following worked to move untracked files:

git add --all

Next, I followed similar steps

 git commit -m "First commit"

Then,

git remote add origin git@github.....

Last but not the least:

git push -u origin master

As you do this, Windows security will pop up asking for your username and password.

Solution 16 - Git

You probably forgot the command git add . after the git init command.

Solution 17 - Git

After the GitHub update 01.10.20 you should use main instead of master.

Do it like these way...

  1. Create a repository on GitHub
  2. Delete existing .git file on your local directory
  3. Go to local project directory and type git init
  4. git add .
  5. git commit -m"My First Commmit"
  6. Now check your branch name it will be master in your local project
  7. git remote add origin <remote repository URL past here from the github repository> then type git remote -v
  8. git push -f origin master
  9. Now check the github repository you will see two branch 1. main 2. master
  10. In your local repository create new branch and the branch name will be main
  11. git checkout main
  12. git merge master
  13. git pull origin main
  14. git push -f origin main

Note: from 01.10.20 github decided use main instead of master branch use default branch name

Solution 18 - Git

My issue was that the 'master' branch hadn't been created locally yet.

A quick

git checkout -b "master"

created the master branch, at which point, a quick

git push -u origin master

pushed the work up to the Git repository.

Solution 19 - Git

Just add an initial commit. Follow these steps:

  • git add .

  • git commit -m "initial commit"

  • git push origin master

This worked for me.

Solution 20 - Git

Feb, 2022 Update:

If your branch is "main":

enter image description here

Run this command:

git push origin main

If your branch is "master":

enter image description here

Run this command:

git push origin master

Solution 21 - Git

Maybe the branch is main instead of master

try

git push origin HEAD:main or git push origin main

Solution 22 - Git

I have faced the same issue,

solved my problem.

just make a branch:

git checkout -b "master"

after that

git push -u origin master

bomm.

hope it will be solved.

Solution 23 - Git

This happens when you have added your file, forgot to commit and pushing. So commit the files and then push.

Solution 24 - Git

This just mean you forgot to do the initial commit, try

git add .
git commit -m 'initial commit'
git push origin master

Solution 25 - Git

  1. First, git add .
  2. Second, git commit -m "message"
  3. Third, git push origin branch

Please check for spelling mistakes because that could also give that error.

Solution 26 - Git

I also followed GitHub's directions as follows below, but I still faced this same error as mentioned by the OP:

git init
git add .
git commit -m "message"
git remote add origin "github.com/your_repo.git"
git push -u origin master

For me, and I hope this helps some, I was pushing a large file (1.58 GB on disk) on my MacOS. While copy pasting the suggested line of codes above, I was not waiting for my processor to actually finish the add . process. So When I typed git commit -m "message" it basically did not reference any files and has not completed whatever it needs to do to successfully commit my code to GitHub.

The proof of this is when I typed git status usually I get green fonts for the files added. But everything was red. As if it was not added at all.

So I redid the steps. I typed git add . and waited for the files to finish being added. Then I followed through the next steps.

Solution 27 - Git

It happens if you forget to commit before pushing for the first time. Just run:

git commit -m "first commit"

Solution 28 - Git

To check the current status, git status.

And follow these steps as well:

git init
git add .
git commit -m "message"
git remote add origin "github.com/your_repo.git"
git push -u origin master

Solution 29 - Git

I had the same problem when I missed to run:

git add .

(You must have at least one file, or you will get the error again.)

Solution 30 - Git

If you get this error while working in detached HEAD mode, you can do this:

git push origin HEAD:remote-branch-name

See also: https://stackoverflow.com/questions/35736116/making-a-git-push-from-a-detached-head

If you are on a different local branch than the remote branch, you can do this:

git push origin local-branch-name:remote-branch-name

Solution 31 - Git

Short answer: This error means the branch you want to push in remote doesn't exist!

In my case, starting from October-2020, the repos created since then had the main branch instead of the previous master branch. So all I had to do this:

git push -u origin main 
  • you may skip -u flag if the upstream is set( Like in case you had cloned it already)

Bingo! That worked for me! Hope that helps! Happy coding!

Solution 32 - Git

I was facing the same issue and tried most of the answers here, But the issue was because of recent changes of Github renaming.

GitHub is gradually renaming the default branch of repositories from master to main.

https://github.com/github/renaming

Your new command would be :

git push origin main

instead of this :

git push origin master

Solution 33 - Git

In the scenario where you check out the code from an external repository (GitHub), and want to import it in personal / internal system, this command really shines:

git push --all origin

This pushes all local branches to the remote, without checking refs and without insisting on commits.

Solution 34 - Git

In 2021 github changed the default branch name to main previously it was master, i suffered because i tried to push to master which did not exist and the branch at remote was main instead, make sure you are using correct branch name.

command below worked for me

git push origin main

Solution 35 - Git

I had the same problem. I did it by the following steps:

1. git commit -m 'message'
2. git config --global user.email "your mail"
3. git config --global user.name "name"
4. git commit -m 'message'
5. git push -u origin master

Solution 36 - Git

This will also happen if you have a typo in the branch name you're trying to push.

Solution 37 - Git

git add .

is all you need. That code tracks all untracked files in your directory.

Solution 38 - Git

In case if you are facing this problem even after doing git init and pushing your initial commit. You can then try the following,

git checkout -b "new branch name"
git push origin "new branch name"

Your code will be pushed as a new branch.

Solution 39 - Git

You need to configure your Git installation if it is the first time that you use it, with:

git config --global user.email "[email protected]"

git config --global user.name "Your Name"

Solution 40 - Git

In end of 2020, GitHub changed its master branch to main branch

I noticed GitHub created a new branch master and this not the main branch when I am using git push -u origin master:

Now when I try to use git push -u origin main, to push directly to main branch it gives me this error:

I faced this error:

src refspec main does not match any
error: failed to push some refs to 'https://github.com/<my_project_name>.git

I fixed using these steps after my first commit to main.Change URL for your GitHub in the following code:

git branch -M main
git remote add origin https://github.com/Sidrah-Madiha/<my_project_url>.git
git push -u origin main

Solution 41 - Git

Double check that you're pushing the correct branch name. I encountered the same error and after looking at git show-ref I was able to see I was typing it in wrong, therefore, no ref.

Solution 42 - Git

git push -u origin master

error: src refspec master does not match any.
error: failed to push some refs to 'http://REPO.git'

This is caused by the repository still being empty. There are no commits in the repository and thus no master branch to push to the server.

It worked for me

Resolution

1) git init
2)git commit -m "first commit"
3)git add app
4)git commit -m "first commit"
5)git push -u origin master

Solution 43 - Git

Github changed the default branch name from master to main. So if you created the repo recently, try pushing main branch

git push origin main

Github Article

Solution 44 - Git

I forgot to do a "git pull origin master" after commit and before push and it caused the same problem: "src refspec master does not match any when pushing commits in git".

So, you should do:

1. git add .
2. git pull origin master
3. git commit -am "Init commit"
4. git push origin master

Solution 45 - Git

This error occurs as you are trying to push an empty repo into the git server. This can be mitigated by initializing a README.md file :

cat > README.md

Then type something, followed by an enter, and a CTRL+D to save. Then the usual committing steps :

git add .
git commit -m "Initial commit"
git push origin master

Solution 46 - Git

To avoid getting into this error in 2021 and onwards, use this command before using git init

git config --global init.defaultBranch main This tells your git to use main as the default branch name always, instead of master

Solution 47 - Git

Try this:

git add .

git commit -m "your commit message"

git remote add origin *remote repository URL*

git push origin *your-branch-name*

Solution 48 - Git

Only commit solved this error:

git commit -m "first commit"

Solution 49 - Git

This worked for me, resetting to remote master the repository:

git checkout master
git commit -a -m "your comment"
git push origin master

Solution 50 - Git

I was getting this error because my local branchname did not match the new remote branch I was trying to create with git push origin <<branchname>>.

Solution 51 - Git

I got this problem while adding an empty directory. Git doesn't allow to push an empty directory. Here is a simple solution.

Create the file .gitkeep inside of directory you want to push to remote and commit the "empty" directory from the command line:

touch your-directory/.gitkeep
git add your-directory/.gitkeep
git commit -m "Add empty directory"

Solution 52 - Git

In my case I cloned a repository, but I didn't switch to the branch locally.

I solved it by doing this:

Before making changes in code you should do this:

git checkout branch-name

Then make changes to your code

After that push the code to the branch:

git push -u origin branch-name

Also, if you are pushing your local repository first time to GitHub, you need to first create a main branch:

git branch -M main

And, then, after adding the origin (or whatever name you give to your remote) push the branch:

git push -u origin main

Solution 53 - Git

I did face the same problem, but in my case the following the exact steps from the beginning as given on the page when you create a new repository worked.

Just pasting that over here:

  echo "# YYYY" >> README.md
  git init
  git add README.md
  git commit -m "first commit"
  git remote add origin https://github.com/XXXX/YYYY.git
  git push -u origin master

Type the above in Git Bash. XXXX being the username and YYYY the repository name.

Solution 54 - Git

What worked for me was simply checkout to the branch that I want my code to push and then simply push your code.

git checkout -b branchname-on-which-i-will-push-my-code

git add .
git commit -m "my commit message"
git push origin branchname-on-which-i-will-push-my-code

Solution 55 - Git

Make sure you are pushing to the right branch or is there any typo. check out your current working branch name with this command
git show-branch

Solution 56 - Git

I also faced the same issue. In my case by mistake I made a commit before adding. After performing the steps in sequential order I got it.

Also please make sure to give the correct branch name.

git init
git add .
git commit -m <Your commit message>
git remote add origin "your repo link here"
git push -u origin master

Thanks. Hope it helps.

Solution 57 - Git

Another possible cause of this problem is if you misspell the branch name. So if you did what I did then the problem would be fixed by correcting:

git push origin mater

to

git push origin master

Solution 58 - Git

Check your commit title, because if you forget the git commit -m "xxxx" command, you get the same problem

git commit -m "initial commit"

Solution 59 - Git

I ran into the same snag..and the solution was to push the code to the repo as though it were an existing project and not a brand new one being initialised.

git remote add origin https://github.com/Name/reponame.git
git branch -M main
git push -u origin main

Solution 60 - Git

First of all make sure that you are using master branch. In my case branch was main instead of master. So what I did was

git push origin main

You can see the result in this photo

Git problem

Solution 61 - Git

I had the same issue just today. I created a new repo and cloned it to my machine. I committed my code and tried to push it. I got the same error. I observed that it is because I was using:

git push origin master

What I was doing wrong here is that I assumed my default branch to be master whereas the new default on GitHub is main. I pushed using:

git push origin main

and it worked fine.

My solution applies only to the newer repos or people facing this issue very recently because GitHub is replacing the main over master terminology. So if you get this error, make sure to check the branch you are pushing to and the branch name on GitHub.

Solution 62 - Git

As one of the options for solving your problem:

git push origin HEAD

Solution 63 - Git

I think it's because you pushed an invalid branch.

Generally, because the repository does not have a common master branch (maybe development branch). You can use

git branch

to see branches.

Solution 64 - Git

I had a similar error. But Git tells me:

*** Please tell me who you are.

Run

git config --global user.email "[email protected]"
git config --global user.name "Your Name"

Or to set your account's default identity.

Omit --global to set the identity only in this repository.

Then the error goes away.

Solution 65 - Git

This happened to me when I did not refer to the master branch of the origin. So, you can try the following:

git pull origin master

This creates a reference to the master branch of the origin in the local repository. Then you can push the local repository to the origin.

git push -u origin master

Solution 66 - Git

Maybe GitHub doesn't know who you are.

First you have to run:

git config --global user.email "[email protected]"
git config --global user.name "Your Name"

Solution 67 - Git

Try git show-ref

You might see refs/heads/live

This means you should do

git push -u origin live

Solution 68 - Git

I forgot to commit then ran to this. JUST COMMIT

Solution 69 - Git

One reason for this month is probably be: github has rename default "master" branch to "main" branch. So, use git push origin main instead.

Solution 70 - Git

Update to previous answers.

Also, don't forget that github has changed 'Master' to 'Main', so make sure you're pushing via:

git push origin main

Solution 71 - Git

In 2020:

If none of the 30+ answers has worked, you probably need to run git push origin main (master has been renamed to main at the time of writing this answer)

Solution 72 - Git

If you want to create a new branch remotely in the origin, you need to create the same branch locally first:

$ git clone -b new-branch
$ git push origin new-branch

Solution 73 - Git

I had already created a commit. Make sure you are pushing to the right branch.

I was typing git push origin master, but when I typed git branch I was on a v1 branch, so I had to type git push origin v1.

Solution 74 - Git

I had the same issue and fixed it using the following steps:

Solution 75 - Git

I created the files in the wrong directory, tried to do git push -u origin master, and I got the error.

Once I cd to the current directory, do git push -u origin master, and all is fine.

Solution 76 - Git

The problem I had was when trying to reset my repository. I wanted to delete all history and commit nothing. However, you have to add at least SOMETHING to commit, so I just created an empty text file, git add . and then git commit -m "Reset repository".

Solution 77 - Git

I had this problem once because i had a branch on my remote repo but not locally. I did:
git fetch && git checkout 'add remote branch name here' and it solved my problem.
Sometimes the problem occurs when you don't stage your changes, so to do this you need to run the following git command:
git add your_file_name.extension or git add . to add all changes.
At this point you need to commit your changes with:
git commit -m 'your commit message here'.
Once you have done all that, you just need to push your changes to remote repo with:
git push origin your_branch_name.

Solution 78 - Git

First you need to git init to create your own .git file, otherwise if you clone someones git folder it will not recognize your git credential. After you started git, then continue with git add. and git commit ...

Solution 79 - Git

You may run into this issue for multiple reasons.

1. Pending commit for the stagged files

If you've added the changes by running git add command(i.e git add .), and never committed those files then after and tried to push the branch into the remote repository. In this case, you'll face the error src refspec master does not match any.

2. Invalid local branch name

If you did a typo in name of branch,(i.e mster instead of master) then it ill lead you to this error. means the branch you're trying to push into is not in the local repository.

Solution 80 - Git

As of 1st October 2020, GitHub is changing the name of the master branch to main. This is what is causing the issue. When someone types git push origin master they see this error
error: src refspec master does not match any error: failed to push some refs to 'https://github.com/username/reponame.git'

This can be fixed by using git push origin main. Hope this helps. I took quite some time to figure out why I couldn't push my commits to the master branch.

Solution 81 - Git

I had faced same issue before, the issue was with my local branch name, it was different from the one I tried to push, correcting branch name to the target one, I was able to push the changes.

Remember the local branch and target branch should be same.

Solution 82 - Git

For Repositories WIKI, I encountered this error also.

git show-branch

if shows master then

git push -u origin master

Solution 83 - Git

I was contributing to one GitHub repository, so I forked the project, cloned it, created my own branch, did some commits, and tried to push.

At this point I discovered that I cloned not my fork, but the original project repository (which I don't have permission to push to).

So I changed the .git/config to point origin to my repository.

At this point, when I tried to push, I was getting the error error: src refspec my_awesome_branch does not match any.

All I had to do was to touch any file and commit it (similar like you see it in this answer):

git touch README
git commit -m "fixing error in my git repo"

And then:

git checkout master
git pull origin master
git push origin master # This will tell my remote repository about my new branch
git checkout my_awesome_branch
git push origin my_awesome_branch # Now it will work

Solution 84 - Git

I faced this exact problem while dealing with VCS in Android Studio. It turns out all I had to do was:

  1. Select all files from the "app" folder;
  2. Go to VCS (Option at top);
  3. "Add" the files;
  4. Committing again via terminal, or by clicking via the drop down menu, and;
  5. Push!

Eureka! :D

Solution 85 - Git

I faced similar error. The error was due to this command

git push -u origin master

subsequent commands worked for me

start with these commands

git init
git add .
git commit -m "second commit"

so before pushing it run these commands to see what remote repository on Github our local repository is connected to and which branch are you on.

git remote
git branch

remote -->origin

branch --> main

git push -u remote branch

or more specifically :

git push -u origin main


Solution 86 - Git

Regarding Aryo's answer: In my case I had to use the full URL of my local Git repository to push the file. First I removed all the files in the current directory and created README added it.

Added some more. Then I committed those files and at last pushed them, giving a proper URL to the repository. Here yourrepository is the name of the repository on the server.

rm -rf *

touch README
git add README
touch file1 file2
git add file1 file2

git commit -m "reinitialized files"
git push git@localhost:yourrepository.git master --force

Solution 87 - Git

Error from Git:

> error: src refspec master does not match any.

Fixed with this step:

git commit -m "first commit"

Before I ran:

git add <files>

And after I ran:

git push -u origin master

Solution 88 - Git

For users of Bash within Cmder on Windows, make sure to create a new .ssh folder in your new home directory.

  1. Go to your home directory cd ~.

  2. Generate ssh keys ssh-keygen.

  3. Leave all inputs blank (keep pressing enter)

  4. Copy the id_rsa.pub file into your Github > Settings > SSH Keys

Solution 89 - Git

I got this error,

> error: src refspec master does not match any.

when I tried to push a commit to GitHub, having changes (at GitHub).

git push -u origin branch-name - helped me to get my local files up to date

Solution 90 - Git

This works for me:

Just checkout the master branch:

git checkout -b master
git add .
git push origin master

Or use --force for forcing a change.

git push origin master --force

Solution 91 - Git

I had the same problem and discovered also that I had not committed any file, so when I tried to commit again, I got this error message:

*** Please tell me who you are.

Run

 git config --global user.email "[email protected]"
 git config --global user.name "Your Name"

 to set your account's default identity.
 Omit --global to set the identity only in this repository.

 fatal: unable to auto-detect email address (got 'USER@WINDOWS-HE6I2CL.(none)')

Then all I did was add my email and name globally and then committed again:

git commit -m 'Initial commit'

Then pushed

git push -u origin master

Solution 92 - Git

If you have Visual Studio Code:

  1. Delete .git folder if you don’t need changes to track (if yes, git stash)
  2. git init
  3. git commit -m "first commit"
  4. git remote add origin https://github.com/YOURusername/YOURrepo.git
  5. By Visual Studio Code UI IDE, GOTO source control from the left hand side panel or (Ctrl + Shift + G)
  6. Stage all your changes or part
  7. Commit your changes
  8. Synchronize your changes by left bottom button (like number or like cloud icon). Then Visual Studio Code wants you to enter your username and password.

If you have permissions to the repository, you can see:

> git push -u origin master
Fatal: AggregateException encountered.
To https://github.com/your_account/yourrepo.git
 * [new branch]      master -> master
> git status -z -u
> git symbolic-ref --short HEAD
> git rev-parse master
> git rev-parse --symbolic-full-name master@{u}
> git rev-list --left-right master...refs/remotes/origin/master
> git for-each-ref --format %(refname) %(objectname) --sort -committerdate
> git remote --verbose
> git show :ionic.config.json
> git check-ignore -z --stdin

Solution 93 - Git

I too faced the same problem. But I noticed that my directory was empty when this error occurred. When I created a sample file and pushed again it worked. So please make sure before pushing that your folder is not empty!!

Solution 94 - Git

March 2021, with Git 2.31:

A git clone of an empty GitHub repository will create a local repository with 'main' as a default branch, even if init.defaultBranch is set on master!

The Git transfert protocol v2, supported by GitHub, will communicate to the client the name of the remote default branch (now main for GitHub) to the local Git repository created by git clone.

That means adding and committing new commits will be done on 'main' branch, even if the Git client still consider master as the default branch.

No more "src refspec master does not match any." on your next push.

Solution 95 - Git

Check that the current branch is master only. I faced the same issue and my branch was main. So running the following command did the work for me:

> git push origin main.

Solution 96 - Git

For Gitlab users, updated version of gitlab will now have 'main' branch as default.

So you can try the following:

git push origin main

Reference: Gitlab new git default branch name is main

Solution 97 - Git

Recently came across this problem, what I did was I checked show-ref using, git show-ref and checked whether

> refs/heads/master

was present.

It was present, still it was not working for me.

As I was writing

 git push origin main

Later I changed this command with git push origin master

and it worked perfectly fine for me.

Solution 98 - Git

None of the above solutions worked for me when I got the src-refspec error.

My workflow:

  • pushed to remote branch (same local branch name)
  • deleted that remote branch
  • changed some stuff & committed
  • pushed again to the same remote branch name (same local branch name)
  • got src-refspec error.

I fixed the error by simply making a new branch, and pushing again. (The weird thing was, I couldn't simply just rename the branch - it gave me fatal: Branch rename failed.)

Solution 99 - Git

I also received this problem, but it was because I accidentally shut down my server before doing the push. This too will cause the same error.

Solution 100 - Git

In my case the issue, occuring on Windows, seemed to have something to do with us adding a prefix like feature\ to branch names. We were trying to create and push a branch with such a prefix (say, feature\branch) but there was already a different branch, with a different name prefixed with Feature\ (say, Feature\otherbranch). This means that on Windows the new branch was placed in the same refs\heads\Feature folder. Git may be case-sensitive but Windows filesystem isn't. It helped once we checked out the local branch named Feature\branch.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionsinooheView Question on Stackoverflow
Solution 1 - GitbaisongView Answer on Stackoverflow
Solution 2 - GitVi.View Answer on Stackoverflow
Solution 3 - GitAryoView Answer on Stackoverflow
Solution 4 - GitVIKAS KOHLIView Answer on Stackoverflow
Solution 5 - GitRedView Answer on Stackoverflow
Solution 6 - GitAndrew EView Answer on Stackoverflow
Solution 7 - Gitaug2uagView Answer on Stackoverflow
Solution 8 - Gitpratik kumarView Answer on Stackoverflow
Solution 9 - GitwilsonfozView Answer on Stackoverflow
Solution 10 - GitSaurabh SinghView Answer on Stackoverflow
Solution 11 - GitJin KwonView Answer on Stackoverflow
Solution 12 - GitArslan Ahmad khanView Answer on Stackoverflow
Solution 13 - GitAswin BarathView Answer on Stackoverflow
Solution 14 - GitIsmail HView Answer on Stackoverflow
Solution 15 - GitAreehaView Answer on Stackoverflow
Solution 16 - GitSumerView Answer on Stackoverflow
Solution 17 - GitiamtheasadView Answer on Stackoverflow
Solution 18 - GitAnthonyView Answer on Stackoverflow
Solution 19 - GitNeeruKSinghView Answer on Stackoverflow
Solution 20 - GitKai - Kazuya ItoView Answer on Stackoverflow
Solution 21 - GitSankalp GourView Answer on Stackoverflow
Solution 22 - GitAlaminView Answer on Stackoverflow
Solution 23 - Gituser993563View Answer on Stackoverflow
Solution 24 - GitxuriView Answer on Stackoverflow
Solution 25 - GitAlwan MortadaView Answer on Stackoverflow
Solution 26 - GitGelView Answer on Stackoverflow
Solution 27 - GitBadr BellajView Answer on Stackoverflow
Solution 28 - GitDinithView Answer on Stackoverflow
Solution 29 - GitneoDevView Answer on Stackoverflow
Solution 30 - GitsnapView Answer on Stackoverflow
Solution 31 - GitDeekshith AnandView Answer on Stackoverflow
Solution 32 - GitAaditya UraView Answer on Stackoverflow
Solution 33 - Gitd.raevView Answer on Stackoverflow
Solution 34 - GitAayush NeupaneView Answer on Stackoverflow
Solution 35 - Gituser3051460View Answer on Stackoverflow
Solution 36 - GitGavinView Answer on Stackoverflow
Solution 37 - GitHuntsManView Answer on Stackoverflow
Solution 38 - GitGovindView Answer on Stackoverflow
Solution 39 - GitasdasdView Answer on Stackoverflow
Solution 40 - GitSidrah Madiha SiddiquiView Answer on Stackoverflow
Solution 41 - GitrabbitwerksView Answer on Stackoverflow
Solution 42 - GitGyan Swaroop AwasthiView Answer on Stackoverflow
Solution 43 - GitshivampipView Answer on Stackoverflow
Solution 44 - GitLackeeeeView Answer on Stackoverflow
Solution 45 - GitRoshin RaphelView Answer on Stackoverflow
Solution 46 - GitSidrah Madiha SiddiquiView Answer on Stackoverflow
Solution 47 - GitPalak JainView Answer on Stackoverflow
Solution 48 - GitOmid AhmadyaniView Answer on Stackoverflow
Solution 49 - GitGiulio RoggeroView Answer on Stackoverflow
Solution 50 - GitAmalgovinusView Answer on Stackoverflow
Solution 51 - GitRajesh KhadkaView Answer on Stackoverflow
Solution 52 - GitLaxminarayan NayakView Answer on Stackoverflow
Solution 53 - GitAnubhav PandeyView Answer on Stackoverflow
Solution 54 - GitVishal VermaView Answer on Stackoverflow
Solution 55 - GitAlmuntasir AbirView Answer on Stackoverflow
Solution 56 - GitVishalView Answer on Stackoverflow
Solution 57 - GitjcwView Answer on Stackoverflow
Solution 58 - GitFerhat KOÇERView Answer on Stackoverflow
Solution 59 - GitRileyMandaView Answer on Stackoverflow
Solution 60 - GitRustamjon KirgizbaevView Answer on Stackoverflow
Solution 61 - GitAyush JainView Answer on Stackoverflow
Solution 62 - GitgorevanovaView Answer on Stackoverflow
Solution 63 - GitZhengming YingView Answer on Stackoverflow
Solution 64 - GitPaket2001View Answer on Stackoverflow
Solution 65 - GitIshrakView Answer on Stackoverflow
Solution 66 - GitAmir.SView Answer on Stackoverflow
Solution 67 - GitJeremiah FlagaView Answer on Stackoverflow
Solution 68 - GitNapster ScofieldView Answer on Stackoverflow
Solution 69 - GitgemfieldView Answer on Stackoverflow
Solution 70 - GitSaltyCatFishView Answer on Stackoverflow
Solution 71 - Gitnz_21View Answer on Stackoverflow
Solution 72 - GitVojtech VitekView Answer on Stackoverflow
Solution 73 - GitespradleyView Answer on Stackoverflow
Solution 74 - GitGujarat SantanaView Answer on Stackoverflow
Solution 75 - GitAliView Answer on Stackoverflow
Solution 76 - GitSina MadaniView Answer on Stackoverflow
Solution 77 - GitAzafoCossaView Answer on Stackoverflow
Solution 78 - GitkutukmuView Answer on Stackoverflow
Solution 79 - GitKiran ManiyaView Answer on Stackoverflow
Solution 80 - GitVishnuView Answer on Stackoverflow
Solution 81 - GitArya MohananView Answer on Stackoverflow
Solution 82 - GitMarkView Answer on Stackoverflow
Solution 83 - Gitequivalent8View Answer on Stackoverflow
Solution 84 - GitDimpy ChhabraView Answer on Stackoverflow
Solution 85 - GitcherryView Answer on Stackoverflow
Solution 86 - GitPramodView Answer on Stackoverflow
Solution 87 - Gitadrian filipescuView Answer on Stackoverflow
Solution 88 - GitJanac MeenaView Answer on Stackoverflow
Solution 89 - GitdiscipleartemView Answer on Stackoverflow
Solution 90 - GitSohailView Answer on Stackoverflow
Solution 91 - GitsamezediView Answer on Stackoverflow
Solution 92 - Gitsaber tabatabaee yazdiView Answer on Stackoverflow
Solution 93 - Gituser9594641View Answer on Stackoverflow
Solution 94 - GitVonCView Answer on Stackoverflow
Solution 95 - GitMuskaan Singla 216View Answer on Stackoverflow
Solution 96 - Gits-labView Answer on Stackoverflow
Solution 97 - GitpsygoView Answer on Stackoverflow
Solution 98 - GitaimangoView Answer on Stackoverflow
Solution 99 - Gitarush436View Answer on Stackoverflow
Solution 100 - GitkamilkView Answer on Stackoverflow