$ git push -u origin main
error: src refspec main does not match any
error: failed to push some refs to 'https://gitlab.com/jay2tinku/my-new-project.git'
If you get such error while performing any git operation. This means you have to check your default branch name. From last few git versions by default branch name is main instead of master. It never means that it will always be main/master. Normally at the time of installation we have to configure that but most of the time we ignore that and go with default options.
Simple fix of this error is :-
git push -u origin master
or
git push -u origin main
Please have a look on below scenario for complete understanding
$ mkdir my-new-project
$ cd my-new-project
$ git status
$ git init
$ cat > test.txt
My first line!!!
$ git status
$ git remote add origin https://gitlab.com/jay2tinku/my-test-project.git
$ git add .
$ git status
$ git commit . -m "Intial push commit"
$ git push -u origin main
error: src refspec main does not match any
error: failed to push some refs to 'https://gitlab.com/jay2tinku/my-new-project.git'
$ git push -u origin master
info: detecting host provider for 'https://gitlab.com/'...
warning: auto-detection of host provider took too long (>2000ms)
warning: see https://aka.ms/gcmcore-autodetect for more information.
info: detecting host provider for 'https://gitlab.com/'...
Enumerating objects: 6, done.
Counting objects: 100% (6/6), done.
Delta compression using up to 8 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (6/6), 504 bytes | 252.00 KiB/s, done.
Total 6 (delta 0), reused 0 (delta 0), pack-reused 0
To https://gitlab.com/jay2tinku/my-new-project.git
* [new branch] master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.
nice
ReplyDelete