Mot
Mot

Reputation: 29520

Remote branch with multiple local tracking branches

Is it possible, that a remote branch can have multiple local tracking branches? Or would that confuse the push/pull commands?

Upvotes: 4

Views: 1748

Answers (2)

Cascabel
Cascabel

Reputation: 496772

It's fine, sort of.

Git looks up remote information for given local branches, not the other way around. That is, the remote branch doesn't have multiple local tracking branches. Multiple local branches have the same remote tracking branch.

When you pull, it fetches the appropriate remote branch, updates the corresponding remote tracking branch, and merges it. Everything will go just fine; only that one branch and its tracked branch are involved. I suspect this is your real use case.

When you push, normally tracking information isn't used at all. The default setting of push.default is matching, i.e. push local branches to remote branches of the same name. In this case, everything will still be fine, trivially so.

However, if you've set push.default to tracking, it'll again look up the right remote branch for each local one - but if your local branches aren't identical, they obviously can't all be pushed there! Probably if you're thinking about multiple local branches tracking the same remote, you simply don't want to set push.default to tracking.

Upvotes: 4

Adam Dymitruk
Adam Dymitruk

Reputation: 129526

there would be no confusion. If anything, it depends on you and how well you understand the way the DAG, branches and remotes work. :)

Upvotes: -2

Related Questions