Reputation: 15435
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:
I'm fairly new to using Git!
Upvotes: 2
Views: 477
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
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
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
Reputation: 18843
origin
.git checkout <branch>
For more details, see git help pull
and git help checkout
.
Upvotes: 0
Reputation: 17091
1) git fetch origin # origin - name of remote repository.
2) git checkout branchName
Upvotes: 1