5

The command git init automatically creates a branch called master as the default branch for a repository.

Aside from being the default name, is master special in any way, or is it just treated as any other branch?

Furthermore, is it treated differently inside of git itself? And is it supposed to be treated differently inside of other software that uses git, i.e. GitHub?

Busti
  • 5,492
  • 2
  • 21
  • 34
  • Besides the two listed duplicates, see also [this answer](https://stackoverflow.com/a/3595134/1256452), which notes that the default merge message is different if the current branch is named `master` than if the current branch is not named `master`. If you rename `master` using `git branch -m`, that affects future commit messages unless/until you rename it back to `master`. – torek Oct 29 '19 at 23:41

3 Answers3

4

Great question. Simple answer: master is not special.

Deeper answer: It is kind of special, because it's a standard convention. It communicates something to other people examining your project. And lots of software, like you discovered, use it by default.

You can find alternate naming strategies out there, like Git Flow. There, master doesn't quite mean the same thing as in a simpler project.

Dogweather
  • 15,512
  • 17
  • 62
  • 81
4

It's not special at all, it's treated just like any other branch. The only reason it's the standard is because you can't have a git repo without at least one branch, when you initialize one with git init, the command creates an initial branch called master, so it became common to use that as the "main" branch of a repository. It's special for its meaning, but not for functionalities, as I understand is your question.

You can rename it with git branch -m new-name, name another branch master, delete it (as long as you still have at least one branch), etc, it works the same way. GitHub sets master as the default branch when someone visits your repo, but you can also change that in settings.

(Source)

julia
  • 153
  • 1
  • 10
3

Aside from being the default name, is master special in any way?

No.

or is it just treated as any other branch?

It's the same as any branch.

Furthermore, is it treated differently inside of git itself?

No.

And is it supposed to be treated differently inside of other software that uses git, i.e. GitHub?

By default, GitHub sets master as the "current" branch. This is the branch that a visitor sees when they view a project. Since master isn't special, GitHub allows you to change the "current" branch to any other branch in the repository's settings.

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268
  • There is one way in which the literal string `master` is special (well, 2 or 3 ways if you count the empty `git init` and the final backstop default for `git clone`), which is the default *merge* message generated by `git merge`. Merge branch X and you get either `merge branch 'X'` or `merge branch 'X' into 'Y'`: the `Y` part is omitted when Y would be "master". – torek Oct 29 '19 at 23:43