Cannot push to main but can push to master

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
error: failed to push some refs to ‘BLAH · GitHub blah blah.git’

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?

1 Like

you may further install GitHub Desktop, through GitHub Desktop, your problem might be solved, it’s just like it’s the middle man between git ang GitHub.

Now, regarding your question, there is no difference. But GitHub decided that instead of master, it should be called main because the term master indicates slavery. So, they decided to change that to main.

1 Like

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:

  1. I create a new repository and try to pull from the master
    $ git pull origin master
    fatal: couldn’t find remote ref master

  2. So, then I try to pull from main, which is successful.
    $ git pull origin main
    remote: Enumerating objects: 3, done.
    remote: Counting objects: 100% (3/3), done.
    remote: Compressing objects: 100% (2/2), done.
    remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
    Unpacking objects: 100% (3/3), 1.09 KiB | 23.00 KiB/s, done.
    From GitHub - OnlineTeachingNow/TileVania: 2D Tile game created in Gamedev.tv's Unity course

  • branch main → FETCH_HEAD
  • [new branch] main → origin/main
  1. However, when I check the available branches, it says there is only a master branch!
    $ git branch
  • master
  1. I commit the files.

  2. I push to the main, which gives me an error.
    $ git push origin main
    error: src refspec main does not match any
    error: failed to push some refs to ‘https://github.com/OnlineTeachingNow/TileVania.git

  3. So, I push to the master, which is successful.
    $ git push origin master
    Enumerating objects: 5031, done.
    Counting objects: 100% (5031/5031), done.
    Delta compression using up to 8 threads
    Compressing objects: 100% (5017/5017), done.
    Writing objects: 100% (5030/5030), 17.01 MiB | 7.67 MiB/s, done.
    Total 5030 (delta 2730), reused 0 (delta 0), pack-reused 0
    remote: Resolving deltas: 100% (2730/2730), done.
    remote:
    remote: Create a pull request for ‘master’ on GitHub by visiting:
    remote: url
    remote:
    url

  • [new branch] master → master

This is absolutely ridiculous! What is the difference between these two? Why can I only pull from main but push to master?

The difference is the name: Your local branch is called master, the remote one main. By default git 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 local master to remote main:

git push origin master:main

However, it might be much easier to rename your local branch to match the remote one:

git branch -m master main
1 Like

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.

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 init.defaultBranch option to let you configure the name of the default branch on init, with the eventual goal of moving away from master (after making sure nothing relies on that name).

1 Like

Got it. Thanks so much for answering my questions. I’ll be renaming the local branch for future projects.

1 Like