How to fetch all remote branch, “git fetch –all” doesn't work
I have looked through other questions on similar question.
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.
> 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
> git pull origin A * branch A -> FETCH_HEAD Already up-to-date. > git branch * master # I think it should show barnch A also
3 Solutions collect form web for “How to fetch all remote branch, “git fetch –all” doesn't work”
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
-b parameter will switch to the new branch after it’s been created. You could also just type:
git checkout A will will auto-name the new branch.
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.
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
# 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.
You need to create the fetched branch locally as well:
git fetch --all && git checkout A