- What's the proper way to add a upstream remote tracking branch?
- How to clone all remote branches including the upstream one?
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 pushed above from Machine-A to GH, and did
git pullon Machine-B. Then in Machine-B, I found I no longer have theremotes/upstream/masterbranch any more, onlyremotes/origin/upstream. I want in Machine-Bupstreambranch still tracking theupstream/masterbranch as in Machine-A. So, I followed "Git Hub Clone All Branches At Once" and did the suggested
git checkout -b upstream origin/upstreamand here is what I got:$ git branch -avv | grep upstream upstream 34e36ed [origin/upstream] added travis-CI ... remotes/origin/upstream 34e36ed added travis-CI ...
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.
- I then tried with answer from "How to clone all remote branches in Git?" and did
git checkout upstream(after deleting the old localupstreambranch of course), because:
If you just want to take a quick peek at an upstream branch, you can check it out directly:
$ git checkout origin/experimentalBut 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.