Cannot push to main but can push to master #22512
-
Hello, all. I am new to Github and have been carefully following several tutorials in order to create my first repository that results in nothing but failure and confusion. When I create a repository, I see that the only branch is labeled as “main”. However, in Git bash, I never see main, my directory is instead labeled “(master)”. However, I assume this is some hangover from this new PC change, so I decided to do everything by referring to the ‘main’ branch, which I have read is no different from the master and is the societally approved way of referring to the most important branch going forward. I do all my pull/commit commands with main, i.e. git pull origin main and it seems to work. However, in the stage of pushing (git push origin main), I get this error: error: src refspec main does not match any I have read over and over again that this is because I didn’t commit properly. However, I commit again and it says: On branch master nothing to commit, working tree clean (so, again, it refers to a master branch that doesn’t exist). So, I changed my push to “git push origin master” and now it adds a master branch to my repository and adds all the project files as expected to that branch. But, now my repository is clearly racist, which implicates me and my products as racist as well. My question is what in the heck is going on? What is the difference between main and master? Why can I not commit to main but can create a master branch and commit to that? Why does Git Bash refer to my main branch as a master branch? If I create a master branch, is the main branch still the master one? |
Beta Was this translation helpful? Give feedback.
Replies: 9 comments 4 replies
-
you may further install GitHub Desktop, through GitHub Desktop, your problem might be solved, it’s just like it’s the middle man between Now, regarding your question, there is no difference. But GitHub decided that instead of |
Beta Was this translation helpful? Give feedback.
-
Thanks for your response. However, there is clearly a difference between Main and Master because I can only use main sometimes and not other times. For example:
This is absolutely ridiculous! What is the difference between these two? Why can I only pull from main but push to master? |
Beta Was this translation helpful? Give feedback.
-
The difference is the name: Your local branch is called
However, it might be much easier to rename your local branch to match the remote one:
|
Beta Was this translation helpful? Give feedback.
-
OK, thank you for the clarification. Would I have to rename the local master branch every time I create a new project? Why is the default on my local branch called ‘master’? I did not create that. Is that the default of Git Bash? Aren’t Git Hub and Bash made by the same people? Why did they decide to be confusingly “antiracist” in one thing, but maintain the “racist” status quo in the other program? The least they could have done is implement consistency. |
Beta Was this translation helpful? Give feedback.
-
OnlineTeachingNow:
Nope. GitHub is a company building on Git. I’m pretty sure some GitHub employees are contributing to Git, but it’s separate. Git somewhat recently (version 2.28) introduced the |
Beta Was this translation helpful? Give feedback.
-
Got it. Thanks so much for answering my questions. I’ll be renaming the local branch for future projects. |
Beta Was this translation helpful? Give feedback.
-
Thank you, this was really annoying me! |
Beta Was this translation helpful? Give feedback.
-
Thanks for your answer. I have been struggling to fight this error for one hour. My local default branch is main, but the remote overleaf branch is still master, so strange errors keep showing up! I will rename my local branch to solve this. Why are all the fuss about master and main? Github should do something more meaningful than just changing those boring names if they really want to stop racisim or other stuffs! |
Beta Was this translation helpful? Give feedback.
-
If the above solution still not works then make a force push. And since this problem will occur just during the first time push no loss of data will occur. |
Beta Was this translation helpful? Give feedback.
The difference is the name: Your local branch is called
master
, the remote onemain
. By defaultgit push origin <branch>
will push that branch to a remote branch of the same name. If you really want to you can override that and explicitly push from your localmaster
to remotemain
:However, it might be much easier to rename your local branch to match the remote one: