Alexander Popov
Alexander Popov

Reputation: 24875

How to automatically track a remote branch when creating a local branch with the same name?

I am using Git on several machines. I must have a configuration, which defers on one of the machines, because in the scenario, where I am on master and have a remote branch origin/foo and want to create a local branch foo, which tracks the remote branch the following happens:

In both cases I get

Branch foo set up to track remote branch foo from origin.

However, the second command works only on one of my machines and on the rest of them it just checks out a local branch foo. Why is that and which setting is responsible for it to work?

P.S. I did the following things, which didn't help:

UPDATE The information that on one of the machines git checkout -b foo works is false. The correct command to checkout a local branch to track a remote is git checkout foo without -b.

Upvotes: 1

Views: 153

Answers (1)

VonC
VonC

Reputation: 1323175

Check if the git version is an older one.

Recent versions of Git should always create a tracking branch with git checkout -b:

If <branch> is not found but there does exist a tracking branch in exactly one remote (call it <remote>) with a matching name, treat as equivalent to

git checkout -b <branch> --track <remote>/<branch>

(or foo is present in more than one remote)
(or you didn't fetch from that remote yet, and it didn't detect the presence of the remote tracking branch origin/foo)

However, it uses git checkout foo, not git checkout -b foo, as the OP Alex Popov confirms in the comments.

Upvotes: 1

Related Questions