hhrzc
hhrzc

Reputation: 2059

src refspec main does not match any: failed to push some refs to git (for existing project)

I need to upload an existing project to my own repository

Preconditions:

Steps:

I followed the given instruction from the git:

git init
git remote add origin https://...`  
git branch -M main
git push -uf origin main

Error:

error: src refspec main does not match any
error: failed to push some refs to 'https://gitlab.com/../...-main.git'

Additional info:


How to resolve this issue?

Upvotes: 2

Views: 5254

Answers (2)

Milind Saini
Milind Saini

Reputation: 11

The error usually occurs when Git can’t find the master branch to push to, often caused by:

  • No committed data in the repository.
  • Mistyping the branch name.
  • Mistyping the branch name.
  • The branch has been renamed.
  • Working with an empty repository.

Upvotes: 1

double-check you have the remote added with

git remote -v 

you should see your remote repository url, then try

git fetch origin main

instead of pushing.

you can push once do the fetching.

Upvotes: 1

Related Questions