20

I have looked through other questions on similar question.

But they seem to say the answer is git fetch --all.

But in my case, it doesn't work.

This is what I have done for it.

> git branch
* master

> git branch -r
origin/master
origin/A

> git fetch --all
> git branch 
* master        #still not updated

> git fetch origin/A
fatal: 'origin/A' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

> git fetch remotes/origin/A
fatal: 'origin/A' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

And I also tried git pull --all also but the result is the same.

-------------------Edit-------------------

> git pull --all
Already up-to-date.

> git branch 
* master              # I think it should show branch A also

> git remote show origin
 HEAD branch: master
 Remote branches:
   A      tracked
   master tracked

-------------------Edit-------------------

> git pull origin A
 * branch            A       -> FETCH_HEAD
Already up-to-date.

> git branch 
* master                   # I think it should show barnch A also
nwinkler
  • 52,665
  • 21
  • 154
  • 168
SangminKim
  • 8,358
  • 14
  • 69
  • 125
  • 3
    1. It's `git fetch origin A` not `git fetch origin/A`. 2. `git pull` will do a `fetch` and a `merge`. `git pull --all` should perform a pull on all **tracked** branches. – noahnu Jul 16 '15 at 04:11
  • From your edit, it looks like it's working. What's the problem? – noahnu Jul 16 '15 at 04:13
  • @noahnu I think `git branch` should show `branch A` as well as `master`. – SangminKim Jul 16 '15 at 04:18
  • Possible duplicate of [git fetch doesn't fetch all branches](https://stackoverflow.com/questions/11623862/git-fetch-doesnt-fetch-all-branches) – Victor Sergienko Jul 20 '17 at 19:00

3 Answers3

29

git branch only displays local branches. git branch -r will display remote branches, as you've seen for yourself.

git branch
*master

git branch -r
origin/master
origin/A

git fetch --all will update the list you see when you type git branch -r but it will not create the corresponding local branches.

What you want to do is checkout the branches. This will make a local copy of the remote branch and set the upstream to the remote.

git checkout -b mylocal origin/A

git branch
master
*mylocal

git branch -r
origin/master
origin/A

mylocal in this case is origin/A. The -b parameter will create the branch if it doesn't exist. You could also just type: git checkout A will will auto-name the new branch.

noahnu
  • 3,479
  • 2
  • 18
  • 40
3

I think what you're really looking for is the git branch -a command. It will show all local and remote branches. Here's an example:

# Only show local branches
$ git branch
* master
  develop

# Only show remote branches
$ git branch -r
  origin/HEAD -> origin/master
  origin/master
  origin/develop
  origin/foo

# Show both local and remote branches
$ git branch -a
* master
  develop
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
  remotes/origin/develop
  remotes/origin/foo

You will notice that all of the branches are there - the command will show both local and remote branches.

The foo branch only exits on the remote, I don't have a local foo branch. To create a local foo branch, I would use the checkout command:

# Create a local 'foo' branch from the remote one
$ git checkout foo
Branch foo set up to track remote branch foo from origin.
Switched to a new branch 'foo'

# Show both local and remote branches
$ git branch -a
* foo
  master
  develop
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
  remotes/origin/develop
  remotes/origin/foo

This should explain what you're seeing locally.

nwinkler
  • 52,665
  • 21
  • 154
  • 168
1

You need to create the fetched branch locally as well:

git fetch --all && git checkout A
Ivan
  • 174
  • 5