joesan
joesan

Reputation: 15435

Git clone with all branches

I did a git clone on a remote url and it cloned the repo locally. I wanted to see what the other branches are on this repo, so I did:

git branch -a

I see the following:

My-MacBook-Pro:My-proj myMac$ git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/b_1.1
  remotes/origin/b_1.2
  remotes/origin/b_2.0
  remotes/origin/b_2.0.1
  remotes/origin/b_2.0.2
  .....

This shows me that I'm currently on master. My questions are:

  1. Have I got all the branches also checked out locally?
  2. How can I switch to a branch?

I'm fairly new to using Git!

Upvotes: 2

Views: 477

Answers (5)

Luc DUZAN
Luc DUZAN

Reputation: 1319

Have I got all the branches

Yes and no, actually you have all the information of the branches on your local repository but all the remote/origin/* branches are "read only". In fact, you need to create "your local branch" that will be linked to a remote branch in order to push on that branch.

How can I switch to a branch?

You can switch to a branch with :

git checkout b_1.1

This one will work only if you have only one remote, otherwise you have to specify a remote with :

git checkout -b b_1.1 origin/b_1.1

Upvotes: 4

Balaji Katika
Balaji Katika

Reputation: 3015

You need to explicitly create the local branch and set it to track a remote branch. You could do it using the command

 git branch --track  <name-of-local-branch> origin/<remote-branch>

Once the new branch is created, you could switch to the branch using

git checkout <branchname>

You may refer to my blog for basics of git and sample commands for most frequently used operations available at http://balajikatika-technical.blogspot.com/2014/12/git-reference.html

Upvotes: 0

Яois
Яois

Reputation: 3858

Have I got all the branches also checked out locally?

Nope.

How can I switch to a branch?

For an existing remote branch called foo, simply do:

 git checkout -b foo origin/foo

Upvotes: 2

Kristj&#225;n
Kristj&#225;n

Reputation: 18843

  1. Yes, you have a complete copy of the repository, including all branches that are on origin.
  2. git checkout <branch>

For more details, see git help pull and git help checkout.

Upvotes: 0

cn0047
cn0047

Reputation: 17091

1) git fetch origin # origin - name of remote repository.
2) git checkout branchName

Upvotes: 1

Related Questions