Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does my 'git branch' have no master?

Tags:

git

I'm a git newbie and I keep reading about a "master" branch. Is "master" just a conventional name that people used or does it have special meaning like HEAD?

When I do git branch on the clone that I have, I only see 1 single branch - the one I'm on. No "master" at all. If I type git checkout master (as I see in alot of tutorials or guides), I get

error: pathspec 'master' did not match any file(s) known to git. 

I'm just confused as to why my clone doesn't have a master that everyone seems to imply that it always exists.

like image 409
aberrant80 Avatar asked Sep 02 '10 04:09

aberrant80


People also ask

How do I make my branch a master?

Rename “{current-branch}” to “master” and push to repository (this will create a new “master” branch still “{current-branch}” will exist). In repository settings, change “Default Branch” to point at “master”.

Is master branch created automatically?

It's the first branch to be created automatically when you create a new repository. By default, this initial branch is named master .

Why do I have main branch instead of master?

GitHub took action based on the Conservancy's suggestion and moved away from the term master when a Git repository is initialized, "We support and encourage projects to switch to branch names that are meaningful and inclusive, and we'll be adding features to Git to make it even easier to use a different default for new ...


2 Answers

To checkout a branch which does not exist locally but is in the remote repo you could use this command:

git checkout -t -b master origin/master 
like image 192
Bunyk Avatar answered Oct 22 '22 00:10

Bunyk


Most Git repositories use master as the main (and default) branch - if you initialize a new Git repo via git init, it will have master checked out by default.

However, if you clone a repository, the default branch you have is whatever the remote's HEAD points to (HEAD is actually a symbolic ref that points to a branch name). So if the repository you cloned had a HEAD pointed to, say, foo, then your clone will just have a foo branch.

The remote you cloned from might still have a master branch (you could check with git ls-remote origin master), but you wouldn't have created a local version of that branch by default, because git clone only checks out the remote's HEAD.

like image 42
Amber Avatar answered Oct 22 '22 00:10

Amber