0

I am unable to push to git master, even master branch is there. I have tried git push -u origin master .

git --version
git version 2.32.0.windows.2

The commands executed .

git init
git add .
git commit -m "first commit"
git branch -M main
git remote add origin http://url
git push -u origin main   **//master is not working** 

enter image description here

main branch is working

enter image description here

I have created a remote repository say git_example and then in the same name created a local repository(git_example) and tried to push it to remote.

D:\WORKSPACE\REACT\ems-backend-springboot>git push -u origin master
error: src refspec master does not match any
error: failed to push some refs to 'https://github.com/subhashisz/ems-backend-boot.git'

D:\WORKSPACE\REACT\ems-backend-springboot>git push -u origin main
Enumerating objects: 67, done.
Counting objects: 100% (67/67), done.
Delta compression using up to 4 threads
Compressing objects: 100% (54/54), done.
Writing objects: 100% (67/67), 68.39 KiB | 1.27 MiB/s, done.
Total 67 (delta 3), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (3/3), done.
remote:
remote: Create a pull request for 'main' on GitHub by visiting:
remote:      https://github.com/subhashisz/ems-backend-boot/pull/new/main
remote:
To https://github.com/subhashisz/ems-backend-boot.git
 * [new branch]      main -> main
Branch 'main' set up to track remote branch 'main' from 'origin'.
subhashis
  • 4,629
  • 8
  • 37
  • 52

1 Answers1

1

You already set your "main" branch as main via the command:

git branch -M main

and set any following "git push" to push to the main branch via the command:

git push -u origin main

so in order to push to master, you need to execute:

git push origin master

also in this stackoverflow question you can find how to change your upstream branch if already set:

git branch branch_name --set-upstream-to origin/branch_name
Dandan Drori
  • 126
  • 8