-1

I was asked to copy my team's remote branch, called v8.1, to my local. I am to do a bug fix against this branch.

In Github, I went to Code, switched to v8.1 and copied the SSH command, running it in Terminal: git clone git@github.company.com:folderName/repoName.git

Later, I realized I had not copied Remote Branch v8.1. I had copied Master. In Terminal, "git branch" reveals only 1 branch: master Is there a way to do a "git checkout -b" from Remote v8.1?

I guess my mental model of Remote Branching is off. Please clarify.

I tried git init w SSH. I'm expecting a copy of Remote Branch as my own feature branch on local.

  • 1
    `git fetch origin && git checkout v8.1` – Guildenstern May 12 '23 at 19:40
  • 2
    The `git fetch origin` part is otiose; `clone` was not a single-branch clone, so it already created remote tracking branches for all branches on the remote. – matt May 12 '23 at 19:48

1 Answers1

1

In Terminal, "git branch" reveals only 1 branch: master Is there a way to do a "git checkout -b" from Remote v8.1? I guess my mental model of Remote Branching is off.

No. Your mental model of local branching is off. You do have all the remote branches. But git branch lists only local branches, and you don't have any unless you make one (because local branches are ... wait for it ... local!) — except that git clone by default automatically makes just one local branch for you, based on the default branch at the remote which in this case was master.

So now just say git switch v8.1 and you will get a new local branch based on the remote tracking branch v8.1 (assuming that there is one, as you claim — you can check by saying git branch --all beforehand, and you probably should).

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • “because local branches are ... wait for it ... local!” This can be a bit confusing. The refs are there, called “remotes”, which are local but not your local ones… they are the “remote-tracking” ones. :) I guess there’s a reason why the comments on [this answer](https://stackoverflow.com/questions/27828404/why-does-git-status-show-branch-is-up-to-date-when-changes-exist-upstream/27828516#27828516) have so many upvotes. – Guildenstern May 12 '23 at 20:04
  • Well, I stand by the way I said it. Local branches are _purely_ local. Remote tracking branches are based on, and occasionally synchronized with, the remote. Anyway I've given the full story [here](https://www.biteinteractive.com/picturing-git-conceptions-and-misconceptions/), I don't need to re-explain it every darned time. – matt May 12 '23 at 20:38