Rectangle 27 124

The problem can be seen when checking the remote.origin.fetch setting (The lines starting with $ are bash prompts with the commands I typed. The other lines are the resulting output)

$ git config --get remote.origin.fetch
+refs/heads/master:refs/remotes/origin/master

As you can see, in my case, the remote was set to fetch the master branch specifically and only. I fixed it as per below, including the second command to check the results.

$ git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
$ git config --get remote.origin.fetch
+refs/heads/*:refs/remotes/origin/*

The wildcard * of course means everything under that path.

This should probably be the accepted answer, as it actually resolved the issue in the original post.

just a side note, I had to add the --replace-all parameter to replace all values on the configuration for my remote.origin.fetch

git clone <url> --branch <branch> --single-branch [<folder>]

branch - git fetch doesn't fetch all branches - Stack Overflow

git branch fetch
Rectangle 27 1018

You can fetch one branch from all remotes like this:

fetch updates local copies of remote branches so this is always safe for your local branches BUT:

Fetch updates local copies of remote branches so this is always safe for your local branches BUT that means:

1) This will not create local branches tracking remote branches, you have to do this manually

git pull --all

So if you will probably want to run:

However, this can be still insufficient. It will work only for your local branches which track remote branches. To track all remote branches execute this oneliner BEFORE git pull --all:

git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done
for remote in `git branch -r`; do git branch --track $remote; done
git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done
git fetch --all
git pull --all

(it seems that pull fetches all branches from all remotes, but I always fetch first just to be sure)

for remote in `git branch -r`; do git branch --track $remote; done
git fetch --all
git pull --all

Run the first command only if there are remote branches on the server that aren't tracked by your local branches.

git fetch --all
git remote update
for remote in `git branch -r`; do git branch --track ${remote#origin/} $remote; done

because your code created local branches named origin/branchname and I was getting "refname 'origin/branchname' is ambiguous whenever I referred to it.

Sorry. I can't imagine that this is what the OP actually wants. The 'pull' command is 'fetch+merge' and the merge part will overlay all the branches on top of one another - leaving one giant mess.

that fetch wouldn't create a new remote branch you still need to check it out with git checkout -b localname remotename/remotebranch

I had to use for remote in `git branch -r`; do git branch --track ${remote#origin/} $remote; done because your code created local branches named origin/branchname and I was getting "refname 'origin/branchname' is ambiguous whenever I referred to it.

git pull --all; for remote in `git branch -r | grep -v \>`; do git branch --track ${remote#origin/} $remote; done
for /F %remote in ('git branch -r') do ( git branch --track %remote) && git fetch --all && git pull --all

branch - How to fetch all git branches? - Stack Overflow

git branch git-branch
Rectangle 27 1018

You can fetch one branch from all remotes like this:

fetch updates local copies of remote branches so this is always safe for your local branches BUT:

git pull --all

However, this can be still insufficient. It will work only for your local branches which track remote branches. To track all remote branches execute this oneliner BEFORE git pull --all:

git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done
git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done
git fetch --all
git pull --all

(it seems that pull fetches all branches from all remotes, but I always fetch first just to be sure)

Run the first command only if there are remote branches on the server that aren't tracked by your local branches.

git fetch --all
git remote update
for remote in `git branch -r`; do git branch --track ${remote#origin/} $remote; done

because your code created local branches named origin/branchname and I was getting "refname 'origin/branchname' is ambiguous whenever I referred to it.

Sorry. I can't imagine that this is what the OP actually wants. The 'pull' command is 'fetch+merge' and the merge part will overlay all the branches on top of one another - leaving one giant mess.

that fetch wouldn't create a new remote branch you still need to check it out with git checkout -b localname remotename/remotebranch

I had to use for remote in `git branch -r`; do git branch --track ${remote#origin/} $remote; done because your code created local branches named origin/branchname and I was getting "refname 'origin/branchname' is ambiguous whenever I referred to it.

git pull --all; for remote in `git branch -r | grep -v \>`; do git branch --track ${remote#origin/} $remote; done
for /F %remote in ('git branch -r') do ( git branch --track %remote) && git fetch --all && git pull --all

branch - How to fetch all git branches? - Stack Overflow

git branch git-branch
Rectangle 27 1006

You can fetch one branch from all remotes like this:

fetch updates local copies of remote branches so this is always safe for your local branches BUT:

git pull --all

However, this can be still insufficient. It will work only for your local branches which track remote branches. To track all remote branches execute this oneliner BEFORE git pull --all:

git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done
git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done
git fetch --all
git pull --all

(it seems that pull fetches all branches from all remotes, but I always fetch first just to be sure)

Run the first command only if there are remote branches on the server that aren't tracked by your local branches.

git fetch --all
git remote update
for remote in `git branch -r`; do git branch --track ${remote#origin/} $remote; done

because your code created local branches named origin/branchname and I was getting "refname 'origin/branchname' is ambiguous whenever I referred to it.

Sorry. I can't imagine that this is what the OP actually wants. The 'pull' command is 'fetch+merge' and the merge part will overlay all the branches on top of one another - leaving one giant mess.

that fetch wouldn't create a new remote branch you still need to check it out with git checkout -b localname remotename/remotebranch

I had to use for remote in `git branch -r`; do git branch --track ${remote#origin/} $remote; done because your code created local branches named origin/branchname and I was getting "refname 'origin/branchname' is ambiguous whenever I referred to it.

git pull --all; for remote in `git branch -r | grep -v \>`; do git branch --track ${remote#origin/} $remote; done
for /F %remote in ('git branch -r') do ( git branch --track %remote) && git fetch --all && git pull --all

branch - How to fetch all git branches? - Stack Overflow

git branch git-branch
Rectangle 27 118

The problem can be seen when checking the remote.origin.fetch setting (The lines starting with $ are bash prompts with the commands I typed. The other lines are the resulting output)

$ git config --get remote.origin.fetch
+refs/heads/master:refs/remotes/origin/master

As you can see, in my case, the remote was set to fetch the master branch specifically and only. I fixed it as per below, including the second command to check the results.

$ git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
$ git config --get remote.origin.fetch
+refs/heads/*:refs/remotes/origin/*

The wildcard * of course means everything under that path.

This should probably be the accepted answer, as it actually resolved the issue in the original post.

just a side note, I had to add the --replace-all parameter to replace all values on the configuration for my remote.origin.fetch

git clone <url> --branch <branch> --single-branch [<folder>]

branch - git fetch doesn't fetch all branches - Stack Overflow

git branch fetch
Rectangle 27 289

To list remote branches:git branch -r

git checkout -b LocalName origin/remotebranchname

This is exactly what I was looking for when I found the question above. I suspect many people looking for how to pull a remote branch definitely don't want to merge the branch into their current working copy, but they do want a local branch identical to the remote one.

Even if the branch is not visible locally, I can do git checkout remotebranchnameand it works. what's the difference with your solution?

Its default behaviour now. Wasn't the case on older git versions. Using git checkout remotebranchname used to just create a new unrelated branch that is named remotebranchname.

branch - How to fetch all git branches? - Stack Overflow

git branch git-branch
Rectangle 27 285

To list remote branches:git branch -r

git checkout -b LocalName origin/remotebranchname

This is exactly what I was looking for when I found the question above. I suspect many people looking for how to pull a remote branch definitely don't want to merge the branch into their current working copy, but they do want a local branch identical to the remote one.

Even if the branch is not visible locally, I can do git checkout remotebranchnameand it works. what's the difference with your solution?

Its default behaviour now. Wasn't the case on older git versions. Using git checkout remotebranchname used to just create a new unrelated branch that is named remotebranchname.

branch - How to fetch all git branches? - Stack Overflow

git branch git-branch
Rectangle 27 27

To track a (new) remote branch as a local branch:

or (sometimes it doesn't work without the extra remotes/):

git checkout -b <local branch> remotes/<remote>/<remote branch>
git remote update
git remote update <remote>
git branch -r

But my problem is that I can't checkout an existing remote branch, because my git client doesn't think it exists. See my question. Note that when I run git fetch followed by git branch -a it does not show all the branches. I had to delete my working directory and re-clone to see the branch dev-gml that a collaborator made. It worked this time, but we will be branching often!

It's been a long time since I first asked this question, and I just got pinged because someone posted afresh. I'm accepting this answer, even though originally nothing actually worked for me. The reason I have finally marked this correct is because I suspect that what (s)he wrote beside Edit: very well might have worked. It is what I would try if I was still facing the problem. HTH

branch - git fetch doesn't fetch all branches - Stack Overflow

git branch fetch
Rectangle 27 26

To track a (new) remote branch as a local branch:

or (sometimes it doesn't work without the extra remotes/):

git checkout -b <local branch> remotes/<remote>/<remote branch>
git remote update
git remote update <remote>
git branch -r

But my problem is that I can't checkout an existing remote branch, because my git client doesn't think it exists. See my question. Note that when I run git fetch followed by git branch -a it does not show all the branches. I had to delete my working directory and re-clone to see the branch dev-gml that a collaborator made. It worked this time, but we will be branching often!

It's been a long time since I first asked this question, and I just got pinged because someone posted afresh. I'm accepting this answer, even though originally nothing actually worked for me. The reason I have finally marked this correct is because I suspect that what (s)he wrote beside Edit: very well might have worked. It is what I would try if I was still facing the problem. HTH

branch - git fetch doesn't fetch all branches - Stack Overflow

git branch fetch
Rectangle 27 289

To list remote branches:git branch -r

git checkout -b LocalName origin/remotebranchname

This is exactly what I was looking for when I found the question above. I suspect many people looking for how to pull a remote branch definitely don't want to merge the branch into their current working copy, but they do want a local branch identical to the remote one.

Even if the branch is not visible locally, I can do git checkout remotebranchnameand it works. what's the difference with your solution?

Its default behaviour now. Wasn't the case on older git versions. Using git checkout remotebranchname used to just create a new unrelated branch that is named remotebranchname.

branch - How to fetch all git branches? - Stack Overflow

git branch git-branch
Rectangle 27 147

Since the original answer completely misses the point and an edit was rejected, here a concise answer:

Assuming that you've got only one remote called origin, this snippet will create local branches for all remote tracking ones:

for b in `git branch -r | grep -v -- '->'`; do git branch --track ${b##origin/} $b; done

Also, 'git pull --all' will update your local tracking branches, but depending on your local commits and how the 'merge' configure option is set it might create a merge commit, fast-forward or fail.

git fetch --all

Also, git pull --all will update your local tracking branches, but depending on your local commits and how the 'merge' configure option is set it might create a merge commit, fast-forward or fail.

This robustifies the solution against branch names containing shell metacharacters (as per pinkeen's comment on the other answer), and avoids spurious error output: git branch -r | grep -v -- ' -> ' | while read remote; do git branch --track "${remote#origin/}" "$remote" 2>&1 | grep -v ' already exists'; done

Are you sure that git pull --all will update all local tracking branches? As far as I can tell it only updates the current branch from all remotes.

Did this. Local branches matching remote branches were not created. What is the git command that simply says "pull all remote branches creating local ones if they do not exist?"

branch - How to fetch all git branches? - Stack Overflow

git branch git-branch
Rectangle 27 146

Since the original answer completely misses the point and an edit was rejected, here a concise answer:

Assuming that you've got only one remote called origin, this snippet will create local branches for all remote tracking ones:

for b in `git branch -r | grep -v -- '->'`; do git branch --track ${b##origin/} $b; done
git fetch --all

Also, git pull --all will update your local tracking branches, but depending on your local commits and how the 'merge' configure option is set it might create a merge commit, fast-forward or fail.

This robustifies the solution against branch names containing shell metacharacters (as per pinkeen's comment on the other answer), and avoids spurious error output: git branch -r | grep -v -- ' -> ' | while read remote; do git branch --track "${remote#origin/}" "$remote" 2>&1 | grep -v ' already exists'; done

Are you sure that git pull --all will update all local tracking branches? As far as I can tell it only updates the current branch from all remotes.

Did this. Local branches matching remote branches were not created. What is the git command that simply says "pull all remote branches creating local ones if they do not exist?"

branch - How to fetch all git branches? - Stack Overflow

git branch git-branch
Rectangle 27 147

Since the original answer completely misses the point and an edit was rejected, here a concise answer:

Assuming that you've got only one remote called origin, this snippet will create local branches for all remote tracking ones:

for b in `git branch -r | grep -v -- '->'`; do git branch --track ${b##origin/} $b; done
git fetch --all

Also, git pull --all will update your local tracking branches, but depending on your local commits and how the 'merge' configure option is set it might create a merge commit, fast-forward or fail.

This robustifies the solution against branch names containing shell metacharacters (as per pinkeen's comment on the other answer), and avoids spurious error output: git branch -r | grep -v -- ' -> ' | while read remote; do git branch --track "${remote#origin/}" "$remote" 2>&1 | grep -v ' already exists'; done

Are you sure that git pull --all will update all local tracking branches? As far as I can tell it only updates the current branch from all remotes.

Did this. Local branches matching remote branches were not created. What is the git command that simply says "pull all remote branches creating local ones if they do not exist?"

branch - How to fetch all git branches? - Stack Overflow

git branch git-branch
Rectangle 27 79

git fetch origin

then they will be all there locally. If you then perform:

git branch -a

you'll see them listed as remotes/origin/branch-name. Since they are there locally you can do whatever you please with them. For example:

git diff origin/branch-name
git merge origin/branch-name
git checkout -b some-branch origin/branch-name

Just found this page on google... this was the actual type of answer I was seeking. I tried the first command but received an error: [$ git fetch --all origin fatal: fetch --all does not take a repository argument] --- Using "git fetch --all" seems to do the trick. Thanks for the lead!

--all

git fetch -all fetches all branches of all remotes. git fetch origin fetches all branches of the remote origin. The later is what the OP was asking.

--all means "all remotes", not "all branches of a given remote". The latter is implied by any fetch from a remote.

OP asked for a solution enabling "branch", not "branch -a".

branch - How to fetch all git branches? - Stack Overflow

git branch git-branch
Rectangle 27 79

git fetch origin

then they will be all there locally. If you then perform:

git branch -a

you'll see them listed as remotes/origin/branch-name. Since they are there locally you can do whatever you please with them. For example:

git diff origin/branch-name
git merge origin/branch-name
git checkout -b some-branch origin/branch-name

Just found this page on google... this was the actual type of answer I was seeking. I tried the first command but received an error: [$ git fetch --all origin fatal: fetch --all does not take a repository argument] --- Using "git fetch --all" seems to do the trick. Thanks for the lead!

--all

git fetch -all fetches all branches of all remotes. git fetch origin fetches all branches of the remote origin. The later is what the OP was asking.

--all means "all remotes", not "all branches of a given remote". The latter is implied by any fetch from a remote.

OP asked for a solution enabling "branch", not "branch -a".

branch - How to fetch all git branches? - Stack Overflow

git branch git-branch
Rectangle 27 79

git fetch origin

then they will be all there locally. If you then perform:

git branch -a

you'll see them listed as remotes/origin/branch-name. Since they are there locally you can do whatever you please with them. For example:

git diff origin/branch-name
git merge origin/branch-name
git checkout -b some-branch origin/branch-name

Just found this page on google... this was the actual type of answer I was seeking. I tried the first command but received an error: [$ git fetch --all origin fatal: fetch --all does not take a repository argument] --- Using "git fetch --all" seems to do the trick. Thanks for the lead!

--all

git fetch -all fetches all branches of all remotes. git fetch origin fetches all branches of the remote origin. The later is what the OP was asking.

--all means "all remotes", not "all branches of a given remote". The latter is implied by any fetch from a remote.

OP asked for a solution enabling "branch", not "branch -a".

branch - How to fetch all git branches? - Stack Overflow

git branch git-branch
Rectangle 27 40

$ git remote update  
$ git pull --all

This assumes all branches are tracked

if they aren't you can fire this in bash

for remote in `git branch -r `; do git branch --track $remote; done

Then run the command.

When I try that I still get the same result as above.

last one worked for me.. with a few git errors

Same as @JacobLowe, I got the error, but it worked anyway; 'fatal: A branch named 'origin/master' already exists.'

branch - How to fetch all git branches? - Stack Overflow

git branch git-branch
Rectangle 27 40

$ git remote update  
$ git pull --all

This assumes all branches are tracked

if they aren't you can fire this in bash

for remote in `git branch -r `; do git branch --track $remote; done

Then run the command.

When I try that I still get the same result as above.

last one worked for me.. with a few git errors

Same as @JacobLowe, I got the error, but it worked anyway; 'fatal: A branch named 'origin/master' already exists.'

branch - How to fetch all git branches? - Stack Overflow

git branch git-branch
Rectangle 27 40

$ git remote update  
$ git pull --all

This assumes all branches are tracked

if they aren't you can fire this in bash

for remote in `git branch -r `; do git branch --track $remote; done

Then run the command.

When I try that I still get the same result as above.

last one worked for me.. with a few git errors

Same as @JacobLowe, I got the error, but it worked anyway; 'fatal: A branch named 'origin/master' already exists.'

branch - How to fetch all git branches? - Stack Overflow

git branch git-branch
Rectangle 27 21

The bash for loop wasn't working for me, but this did exactly what I wanted. All the branches from my origin mirrored as the same name locally.

git fetch origin '+refs/heads/*:refs/heads/*'
fatal: Refusing to fetch into current branch refs/heads/master of non-bare repository
git checkout <SHA>
git checkout --detach # detach the head
git fetch origin \'+refs/heads/*:refs/heads/*

This one worked for me, except I also use the --tags parameter. I wish there was a standard, simple front end for git, the number of simple things in git that need 10-plus stack overflow answers is ridiculous!

@kristianp Have you checked out Ungit or GitKraken?

@dragon788 I've been using SourceTree for a git GUI, but I was really talking about a simpler command-line for scripting tasks.

branch - How to fetch all git branches? - Stack Overflow

git branch git-branch