the first line shows you the branch that you are on master
and you try to push to main
So you either do:
git remote add main URL
or just do git push origin master.
You can check which origins you have by using git remote -v
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello,
I wonder why I get the following error:
ACER@DAVY MINGW64 /e/xampp76/htdocs/masterlink_web_laravel (master)
$ git push origin main
error: src refspec main does not match any
error: failed to push some refs to 'https://gitlab.com/davy_yg/masterlink.git'
I already:
git add . git commit -m 'initial commit'
the first line shows you the branch that you are on master
and you try to push to main
So you either do:
git remote add main URL
or just do git push origin master.
You can check which origins you have by using git remote -v
git show-ref will show you what the remote repo has.
@tykus ACER@DAVY MINGW64 /e/xampp76/htdocs/masterlink_web_laravel (master) $ git show-ref 4ea200e6d62aee7ee1a88e8052e975b4bdb0f844 refs/heads/master 044c854cc85249ce06369232a303c6ede4a3b0f7 refs/remotes/origin/main 4ea200e6d62aee7ee1a88e8052e975b4bdb0f844 refs/remotes/origin/master
ACER@DAVY MINGW64 /e/xampp76/htdocs/masterlink_web_laravel (master)
$ git push origin master
Everything up-to-date
Now, I checked my gitlab and the only file that exist is readme. That's is strange, since I have the whole laravel apps that I want to push.
Which branch is it main or master?
There should not be any other branch besides main or master.
@davy_yg why is there master and main?
@tykus That's what I don't understand. I thought gitlab only use main. I wonder why there is both? I thought master only for github.
@davy_yg if you git push -u origin master then there will be a master on the remote no matter if Github or Gitlab.
So, (i) what is the correct main branch for your repo, and (ii) what remote branch actually has the history?
I checked my gitlab: master 4ea200e6 · first commit · 35 minutes ago 1 1
main default protected 044c854c · Initial commit · 1 hour ago
ACER@DAVY MINGW64 /e/xampp76/htdocs/masterlink_web_laravel (master) $ git checkout -b main Switched to a new branch 'main'
ACER@DAVY MINGW64 /e/xampp76/htdocs/masterlink_web_laravel (main)
I actually wonder which one is my primary branch ?
Gitlab mentions that my default branch is main.
@davy_yg generally, yes master is the main branch.
What is the true main branch; what is the output from:
git log --graph --simplify-by-decoration --pretty=format:'%d' --all
@tykus ACER@DAVY MINGW64 /e/xampp76/htdocs/masterlink_web_laravel (main) $ git log --graph --simplify-by-decoration --pretty=format:'%d' --all
So the main branch could be either master or main ? not always master or always main ?
@davy_yg that depends on how you set up your repo. You can move the incorrect local branch from master to main:
git branch --move master main
Then set the upstream:
git push --set-upstream origin main
I did this and it moves to main:
ACER@DAVY MINGW64 /e/xampp76/htdocs/masterlink_web_laravel (master)
$ git checkout -b main
Switched to a new branch 'main'
ACER@DAVY MINGW64 /e/xampp76/htdocs/masterlink_web_laravel (main)
$ git add .
ACER@DAVY MINGW64 /e/xampp76/htdocs/masterlink_web_laravel (main)
$ git commit -m 'initial commit'
On branch main
nothing to commit, working tree clean
ACER@DAVY MINGW64 /e/xampp76/htdocs/masterlink_web_laravel (main)
$ git push origin main
To https://gitlab.com/davy_yg/masterlink.git
! [rejected] main -> main (non-fast-forward)
error: failed to push some refs to 'https://gitlab.com/davy_yg/masterlink.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
but still unable to push it to main
I cannot delete main since it's default. All my data is in master. I am trying to simplify my project gitlab so that it only have one main branch.
what does this code do?
git branch --move master main
Then set the upstream:
git push --set-upstream origin main
Move the master content in gitlab from master to main ?
@davy_yg why did you do this?
git checkout -b main
I explained to you how to move the master branch to main; and set the upstream for the main branch.
Please or to participate in this conversation.