0

I am only trying to access a single branch, not all branches as in the the so-called duplicate questions.

Clone another users repository

git clone https://ijabz@bitbucket.org/mvmn/jaudiotagger.git

When I try to list branches it shows nothing

git branch

It shows nothing, even though they do have branches.

e.g https://bitbucket.org/mvmn/jaudiotagger/src/generics_refactoring/

I'm trying to access the generics_refactoring branch

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Paul Taylor
  • 13,411
  • 42
  • 184
  • 351
  • Try `git branch -a`. By default only local branches are shown. – Joachim Sauer Oct 08 '21 at 10:26
  • https://stackoverflow.com/search?q=%5Bgit%5D+clone+all+branches – phd Oct 08 '21 at 10:49
  • Esp. look at https://stackoverflow.com/a/4754797/7976758, https://stackoverflow.com/a/7216269/7976758, https://stackoverflow.com/a/16563327/7976758, https://stackoverflow.com/a/19644027/7976758 – phd Oct 08 '21 at 10:51

1 Answers1

2

git branch only lists local branches.

To see remote branches, try git branch -r (or git branch -a for local + remote)

You might also need to git fetch beforehand to have fresh references.

Once you have checked out a branch locally, it will create a local version, which will indeed appear in the git branch output.

Romain Valeri
  • 19,645
  • 3
  • 36
  • 61
  • Oka that works. does that mean gitclone only downloads the master branch ? I want on my local machine to switch to a particular remote branch so what would be the command needed to get and then switch to particular branch locally – Paul Taylor Oct 08 '21 at 10:32
  • You can just `git checkout ` (**without** the `origin/` prefix or it will just checkout the commit and detach `HEAD`) and it will create a local version, already set to push/pull to said remote branch. `git clone` does get all branches as remote references, but doesn't automatically create local counterparts for them. – Romain Valeri Oct 08 '21 at 10:33
  • Wont that just create a new local branch that happens to have same as remote branch, or will that actually get the remote branch ? – Paul Taylor Oct 08 '21 at 10:37
  • @PaulTaylor It will make the new branch point at the same commit the remote branch points to at the moment of creation, **and** link them for push/pull operations. – Romain Valeri Oct 08 '21 at 10:38
  • ok i did git checkout origin/generics_refactoring and that has worked, thanks – Paul Taylor Oct 08 '21 at 10:48
  • Note that you don't usually manipulate `origin/*` references directly at all, because they are meant to track what the remote repository has (i.e. if you commited onto that, git would get confused on the next pull). So the "local branch that happens to have that as upstream" is exactly what you'd normally interact with. And obviously you can never **truly** check out the remote branch, because that's by definition on the remote end. What you have (as `origin/generics_refactoring`) is [the remote-tracking branch](https://git-scm.com/book/en/v2/Git-Branching-Remote-Branches). – Joachim Sauer Oct 08 '21 at 11:50