Why does "git push main" work on GitHub when "git push master" does not? Also what is difference between "Main branch" and "Master branch"?
GitGithubGit Problem Overview
I tried git push
on my master branch, but it just shows that I have a new pull request. When I click on the new pull request, it takes me to the comparing changes view, but doesn't show any option to add those changes into repository. It only shows the changes I made:
When I entered the command
git push origin main
all files where added to my repository.
but when I do
git push origin master
it doesn't work. Why is that? I heard they are replacing master with main. So in the future are they going to remove master?
Git Solutions
Solution 1 - Git
From the ZDNet article, GitHub to replace "master" with alternative term to avoid slavery references:
> GitHub is working on replacing the term "master" on its service with a neutral term like "main" to avoid any unnecessary references to slavery,
About renaming your branch from master to main, there are a lot of guidelines. For example:
git branch -m master main \
git push -u origin main \
git remote set-head origin main
Solution 2 - Git
They just changed the default branch for new repositories. You can also set it back to master
here -> https://github.com/settings/repositories
Solution 3 - Git
The main
branch has already replaced all new github repos as the main branch. You can read up on it here. There is no actual difference between main and master, it's just the name of the default branch.
For you git push origin master
just creates a new branch called master (since it doesn't exist already) and pushes your current commits there.
Solution 4 - Git
You can follow these instructions:
At first create a repo at GitHub. Then go into your local folder. Open a console. Enter these commands one after the other.
git init
Initialises git in your local folder.
git remote add origin https://github.com/...
Clone your Github repo.
git pull origin main
Calibrate repos. The "main" means that in this case the content of the main branch is copied to the local repo. Other branches can be created in addition to the master branch, but I will not go into this in detail. For the beginning, it is sufficient to have a simple master branch.
git branch -m master main
So what are we doing here? First with the -m command we are moving the git history from master to a new branch called main.
git add .
The locale directory is uploaded to the Github server.
git commit -m "your commit message"
git push --set-upstream origin main
After the commit has been created, the remote repo can be updated on GitHub. When uploading for the first time ("push"), you have to specify which branch should be the default for pushes. In our case, this should again be the master branch in the "origin" repo
Solution 5 - Git
GitHub is working on replacing the term "master" on its service with a neutral term like "main" to avoid any unnecessary references to slavery, its CEO said on Friday.
Now commands look likes this:
git push -u origin main
git remote set-head origin main
It’s not updated in Enterprise yet but it already reflected in the community edition.
Update: You can change back main
to master
from repository settings.
Solution 6 - Git
When i wanted to upload my files to gitlab i had this problem and used this :
git branch -m master main
References :
Solution 7 - Git
You can just follow the instructions:
Before, check if your branch is named "master" (old branches, changed to "main") or "main".
>>For branch "main" otherwise use "master" (old branches)
To push to the upstream branch on the remote, use:
git push origin HEAD:main
To push to the branch of the same name on the remote, use:
git push origin HEAD
To choose either option permanently, see push.default
in git help config
.