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?

kawnah
  • 3,204
  • 8
  • 53
  • 103

3 Answers3

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.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • ok...so how do I fetch those remotes into local? `git fetch --all` doesn't work – kawnah Nov 13 '18 at 20:50
  • @kawnah By checking first if there is anything to actually fetch: check on your remote repo if those branches are there. – VonC Nov 13 '18 at 20:51
  • There are remote branches to fetch, yes. So howcome fetch doesn't work? – kawnah Nov 13 '18 at 20:55
  • 1
    @kawnah From your output, git fetch has worked. You can make those remote trakcing branches local if you want: https://stackoverflow.com/q/379081/6309 – VonC Nov 13 '18 at 21:14
1

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
Mark Bramnik
  • 39,963
  • 4
  • 57
  • 97
  • No, git fetch --all does not fetch all branches: what the documentation (https://git-scm.com/docs/git-fetch#git-fetch---all) actually says it that it fetches from all remotes. The refspec (https://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. – VonC Nov 09 '18 at 07:07
1

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.

kawnah
  • 3,204
  • 8
  • 53
  • 103
  • Yes, that is what I mentioned in the comments of my own answer. i have edited it to reflect that comment. – VonC Nov 27 '18 at 15:43