xpt
xpt

Reputation: 23054

To clone all remote branches including upstream

I know this will be quickly marked as duplicate, but please read the whole post before making such decision. Especially, verify that the two *included answers* are not what you are proposing, and verify that what you proposed can solve my specific question, but not just *seems* similar in title.

For question one, I did git remote add upstream and got a remote tracking branch of remotes/upstream/master then git checkout a local branch. Here is my result (I'm not sure if it is in the correct stage as I was expecting one remote one local):

$ git branch -avv | grep upstream
  upstream                         34e36ed [upstream/master] added travis-CI ...
  remotes/origin/upstream          34e36ed added travis-CI ...
  remotes/upstream/master          34e36ed added travis-CI ...

Now the real trouble is question two.

I.e., instead of upstream/master, the local upstream is tracking origin/upstream, which is no longer a remote tracking branch any more -- I don't see how it links with remotes/upstream/master.

If you just want to take a quick peek at an upstream branch, you can check it out directly:

$ git checkout origin/experimental

But if you want to work on that branch, you'll need to create a local tracking branch which is done automatically by:

$ git checkout experimental

However the local upstream is the same, still tracking origin/upstream, instead of remotes/upstream/master:

    $ git branch -avv | grep upstream
      upstream                         34e36ed [origin/upstream] added travis-CI ...
      remotes/origin/upstream          34e36ed added travis-CI ...

Hence, the two questions at the top of post, both closely related with proper way to setup upstream remote tracking branch.

Upvotes: 0

Views: 114

Answers (1)

phd
phd

Reputation: 94827

What's the proper way to add a upstream remote tracking branch?

There is no.

How to clone all remote branches including the upstream one?

There is no simple way. Though remote-tracking branches are called branches they're not really branches, they are a special kind of reference. AFAIK git protocol doesn't expose them so there is no way to pull or push them.

If you have ssh access to run commands in the remote repository you can try to work with them manually. Periodically run ssh origin git branch -r; that gives you a list of remote-tracking branches in the remote repository. Process the list looking at what commit every reference points and create branches in your local repository pointing to the same commit.

Upvotes: 1

Related Questions