StackPeter
StackPeter

Reputation: 342

Why after command git branch I see origin/master instead of master

my mate tried to clone sources from git branch. When I tried on his machine "git branch", it outputs: origin/master. I have cloned the same sources but after git branch I saw always output: master. I read that origin/master means remote branch and I don't understand why he sees remote branch instead of local branch. What can be reason of problem ?

Upvotes: 0

Views: 1228

Answers (2)

Yurii Hierts
Yurii Hierts

Reputation: 1920

I think an answer is quite simple, your friend checked out to an origin/master insted of master. Execute cmd:

git branch --all

In list of shown branches try to find branch master, and if no such branch, just checkout to it

git checkout master

And then delete origin/master from local copies

git branch -D origin/master

Upvotes: 2

LightBender
LightBender

Reputation: 4253

This is most likely caused by the disambiguation of references as it is possible to name a local branch origin/master.

See Git Revisions Documentation for details, but to summarize, when resolving a reference it checks the following locations in sequence and returns the first match:

$GIT_DIR/<refname>
$GIT_DIR/refs/<refname>
$GIT_DIR/refs/tags/<refname>
$GIT_DIR/refs/heads/<refname>
$GIT_DIR/refs/remotes/<refname>
$GIT_DIR/refs/remotes/<refname>/HEAD

Look in your friend's repository and you'll find this file $GIT_DIR/refs/heads/origin/master. If so, everything is working correctly and he's just got an ambiguous reference. He'll want to change his local branch name to remove the ambiguity so there are no unexpected issues from the disambiguation.

This usually occurs on checkout when you type git checkout -b origin/master instead of git checkout -b master origin/master

As a side note, your local branch name is just a pointer to a commit, so it doesn't really matter what it's named (as long as it's not ambiguous). When pushing to a remote, you update the remote's branch based on the local branch's remote settings, so your local branch name will never be seen by anyone else.

Upvotes: 1

Related Questions