2

What would be a reason for git fetch got fetching remote branches?

How do I check out a remote Git branch?

All I do is run git fetch - I then see

C:\site\blog>git fetch *master

I expect to see something like:

C:\site\blog>git fetch *master origin/branch1 origin/branch2

git fetch doesn't fetch all branches

I run the command in the accepted answer

git config --get remote.origin.fetch

The output of the command is

+refs/heads/*:refs/remotes/origin/*

From what I understand this indicates that I'm not only tracking master but all remotes.

What's wrong? How do I fix this? What would be a reason you can't git fetch? Why is it broken?

running git fetch -a doesn't do anything either.

running git branch -avv gives me the following:

enter image description here

So why does git fetch not work?

3 Answers 3

3

Track all remote git branches as local branches

for i in `git branch -a | grep remote | grep -v HEAD | grep -v master`; do git branch --track ${i#remotes/origin/} $i; done

It's wrong terminology. It's tracking remote branches as local.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, that is what I mentioned in the comments of my own answer. i have edited it to reflect that comment.
2

I don't know whether this can count as a full answer, but thats what I use in a day-to-day job:

git fetch --all

to fetch all branches

Its written in git documentation

In order to see which branches are local and which have a "remote counterpart", I use

git branch -vv

If the branch description (one line per branch has something like [origin/....] it has a remote branch as well, otherwise it's only a local branch)

If I want to see what remote repositories are configured at all (say in a new project that already cloned from somewhere but I don't remember from where) I check that both fetch and push repos are set up:

git remote -v

1 Comment

No, git fetch --all does not fetch all branches: what the documentation (git-scm.com/docs/git-fetch#git-fetch---all) actually says it that it fetches from all remotes. The refspec (stackoverflow.com/a/42728970/6309) associated to those remotes remains key in order to known which branches are fetched. The rest is already in my answer.
2

Check first if those branches were not already fetched:

git branch -avv

If there are no new commits on those branches, a git fetch would not fetch anything.

Check also if those branches are indeed there on the remote repo side (the one referenced by origin, in git remote -v)

To make sure you see all remote branches, you can declare them as local ones, as I do here.

4 Comments

ok...so how do I fetch those remotes into local? git fetch --all doesn't work
@kawnah By checking first if there is anything to actually fetch: check on your remote repo if those branches are there.
There are remote branches to fetch, yes. So howcome fetch doesn't work?
@kawnah From your output, git fetch has worked. You can make those remote trakcing branches local if you want: stackoverflow.com/q/379081/6309

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.