I have a question about "git pull". Suppose I have a two remote branches "master" and "new_branch", when I use "git pull" and then use "git branch", only the "master" is shown. Why I can't see the "new branch"? I have to use "checkout new_branch" to get it shown on the local branch list. How does "checkout" work? Does it change to both local branch and remote branch?
Asked
Active
Viewed 792 times
2 Answers
1
Git won't arbitrarily create local branches for you without you telling it to. However, it does keep track of the remote branches that it knows about.
$ git branch -a
will show you all the available branches on all of your remotes

Gareth
- 133,157
- 36
- 148
- 157
1
Try
$ git fetch --all
it'll fetch all available branches from remote. You'll get a list like
From
* [new branch] a_new_branch -> origin/a_new_branch
* [new branch] b_new_branch -> origin/a_new_branch
3ea1234..1dz3 a_exist_branch_at_local -> origin/a_exist_branch_at_local
3ea1234..1dz4 b_exist_branch_at_local -> origin/b_exist_branch_at_local
Then just checkout the new one you want:
$ git checkout a_new_branch
for old ones (exist at local), you can
$ git checkout a_exist_branch_at_local
$ git merge origin/a_exist_branch_at_local

Kjuly
- 34,476
- 22
- 104
- 118
-
1`git fetch --all` retrieves all the remote branches; `git fetch` by itself only retrieves the upstream branch of the currently checked-out branch. – chepner May 02 '15 at 16:24
-
@chepner seems so, but i can get all w/o the `--all`... anyway, updated the answer to append the `--all` option, thx for the tip :) – Kjuly May 02 '15 at 23:33