2

I'm working on understanding the basic concepts of git.

I've already set up and cloned a remote repository. I'm following a tutorial. My problem is that I don't understand the difference between:

origin/main and origin/master

On the tutorial, it appears origin/master when he types git status on the terminal. On my terminal, it appears:

On branch main

Your branch is up to date with 'origin/main'

I'd like to understand why I'm get origin/main and not origin/master.

Ana Claudia
  • 501
  • 6
  • 16

3 Answers3

5

master is the old name of Git's (and GitHub's) master branch. This term is deemed offensive, and invokes connotations of slavery. About a year ago, Git and GitHub changed the name of the default branch to the more neutral main.

Some projects have switched over, and some projects kept the old name master. From a technical perspective, it's just a name - you can create a project with a default branch called main, master or spongebob-squarepants.

Mureinik
  • 297,002
  • 52
  • 306
  • 350
  • 1
    Note that this only affects GitHub, GitLab and a few such remote hosting sites. This has not been changed in Git itself, and creating a new local repo with Git will still initialize it with a master branch. – Spacejet Jan 27 '23 at 22:16
4

it was called master in the past. Now people use main instead. Basically the same.

tm243
  • 109
  • 2
1

When you clone some existing repository, you get all of their commits1 and none of their branch names. But they still do have branch names. What your Git does with those is turn them into your own remote-tracking names.2

A remote-tracking name like origin/master or origin/main is your Git's way of remembering one of their Git's branch names.3 So if they have a branch named main, you get a remote-tracking name origin/main. If they have a branch named master, you get a remote-tracking origin/master.

Once git clone has finished copying their commits into your repository, and renaming their branch names to your remote-tracking names, your Git then creates one branch name in your repository. You choose which branch name your Git should create, using the -b option to git clone:

git clone -b develop https://example.com/path/to/repo.git

for instance.

If you don't give a -b option, your Git asks their Git which name they recommend. Depending on who "they" are, they may recommend either master or main.

There's one thing that's a bit peculiar here, and that is that your Git demands that this name you select match one of their names. Since your names are yours, and their names are theirs, and the two need not match up,4 there is no real requirement for this, but your Git still demands it anyway, probably in an attempt to reduce confusion. So if they have only main, or only master, that's the name you'll get.

The (single) standard first name used to be master. Then GitHub changed theirs to main and now there is confusion. If you create a repository from scratch—rather than cloning it—you can choose any initial branch name you want.5


1Technically, you can get fewer than all of their commits, but the usual case is that you get them all.

2Git calls these remote-tracking branch names, but they are not branch names: git switch origin/main gives you an error, for instance, and git checkout origin/main produces what Git calls a detached HEAD. Meanwhile, the word branch is very badly over-used in Git. So it makes more sense to drop the word branch from this phrase. These names are just names in your repository that remember someone else's branch names; we could call them "crimson names", but they do in fact track some "remote" Git's branch names, so remote-tracking is sort of reasonable.

3By "your Git", I mean "your Git software, working within your repository". "Their Git" is thus their software working within their repository.

4That is, you can call one of your branches dwayne while they call one of theirs rapunzel, and yet you can still make your commits on your dwayne match up with theirs on their rapunzel. It's just ... confusing to do this. Humans seem to prefer to use the same name on both sides when the goal is to have the same commits on both sides too.

This idea can go awry: if you have two different remotes, such as bob to connect to Bob's Git and alice to connect to Alice's, and both bob and alice have a branch named cream but one refers to a dairy product and the other to the 1960s band, you're not going to be able to have one branch in your repository named cream that somehow works for both of these. So Git doesn't require it, except during this initial git clone step.

5This requires a reasonably up-to-date Git to do it with the git init command. With older versions of Git, you do the git init and get started with the name master, then rename the branch.

torek
  • 448,244
  • 59
  • 642
  • 775