Reputation: 9136
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
Upvotes: 22
Views: 49321
Reputation: 3574
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.
Upvotes: 30
Reputation: 54457
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.
Upvotes: 3
Reputation: 164
You need to create the fetched branch locally as well:
git fetch --all && git checkout A
Upvotes: 0