0

I'm new and I'm lost. I read now "master" is renamed to "main" due to its slavery terminology. So I did git push origin main from my PC console and I get the error error: src refspec main does not match any. But my branch is called main not master. So why the error? I've added and committed prior.

wipor20530
  • 23
  • 4
  • It depends on many things - what your current branch on local is? If you are already on 'main' or 'master', you can simply do a 'git push'. These are very basic things you can find by searching on Google, it is very much appreciated if you do some search yourself before asking on SO. Anyway, welcome to SO :) – rsp Feb 03 '22 at 06:16
  • 1
    See [this SO question](https://stackoverflow.com/questions/30590083/how-do-i-rename-both-a-git-local-and-remote-branch-name) for how to handle this situation. Your push command is wrong, because your local branch is now called main, not master, but the remote branch is still called master. – Tim Biegeleisen Feb 03 '22 at 06:18
  • Sorry, how do I know my local branch? What I did was `git init`, `git add .`, `git commit - m "blabla"`, `git remote add origin `, and then `git push origin main` – wipor20530 Feb 03 '22 at 06:19
  • @TimBiegeleisen But my remote is called "main" -> https://nimb.ws/HoAPIU and after I ran `git push origin master`, I have two branches - main and master. – wipor20530 Feb 03 '22 at 06:21

2 Answers2

0

You can always check it with the git branch command to confirm.

You can use this command to set Default branch name system wide.
git config --global init.defaultBranch main

  • Gee, it's called master. But why master when github says we gotta get rid or slavery so now it's called main? My github ver too old? Great now I have to figure out how to know my github version and how to update it. I just wanna submit a proposal form to a repo. – wipor20530 Feb 03 '22 at 06:29
  • I just did `git config --global init.defaultBranch main` and `git branch -m ` and then `git push -u origin main` and I get `error: failed to push some refs to...` – wipor20530 Feb 03 '22 at 06:32
  • The configuration only changes the default branch for new repositories, if you want to do that for existing repo, use `git branch -m new-branch-name`. – Rachit Kumar Pandey Feb 04 '22 at 11:42
0

It's because there is an error in the connection between git and github, I tried to login to github many times to authenticate in git terminal, but still can't. then I tried in the vscode terminal. At first it didn't work, although I've tried using main and master, they both didn't work. Then after the umpteenth attempt to push, vscode somehow automate the authentication so I can use main to push again.

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 03 '22 at 14:40