130

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:

Screenshot of different branches

Screenshot of the GitHub Compare Changes view showing no changes

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?

Prathu9
  • 1,413
  • 2
  • 9
  • 12
  • As an additional tip to the answers: you can set the default branch in Github settings either for a specific project and/or also for all new projects. – simon Nov 19 '20 at 16:25

7 Answers7

171

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
TylerH
  • 20,799
  • 66
  • 75
  • 101
minion
  • 1,889
  • 1
  • 8
  • 9
  • 5
    Does this apply just to github or will the default in git change also? If you use bitbucket or other servers you will not be affected? – Dabaus Aug 18 '21 at 11:13
  • 1
    It's for github only, to be sympathetic to progre movements, it doesn't have any validity with the actual git mechanism. – e-info128 Jan 24 '23 at 23:45
46

They just changed the default branch for new repositories. You can also set it back to master here -> https://github.com/settings/repositories

Unglückspilz
  • 1,820
  • 19
  • 25
22

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.

tistorm
  • 381
  • 1
  • 8
8

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

Mr.Head3437
  • 156
  • 2
  • 4
4

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.

Alok Tripathi
  • 874
  • 10
  • 9
0

When i wanted to upload my files to gitlab i had this problem and used this :

git branch -m master main

References :

How to Rename the master branch to main in Git

Change Default Branch - Locally and Gitlab

-2

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.

marcfreir
  • 71
  • 1
  • 3
  • Thanks for the correction @Zsolt Meszaros. I just highlighted the commands with bold, but didn't work well. – marcfreir Jan 20 '21 at 15:43
  • As answered above (the other comments) - GitHub is replacing the term "master" to "main" (without quotes) for the new repos. – marcfreir Jan 20 '21 at 15:49