I have several local clones of a remote repo. Working in one of them, I update some branches and push to the remote. I then go to another different clone, and I want to fetch and update my remotes cached here in this other local repo.
I have a procedure which works fine, but is manual. Here's an example. First, working in the first local clone repo, I do some changes to branch1,branch2 and branch3, then push. Next, over in the other local clone of the same remote repo, I am wanting to bring its cached copies of the remotes up to date, so I do this...
$ git fetch
...says remote counting objects, unpacking etc then a series of lines like...
eb7b3000..67f0ade3 mybranch1 -> origin/mybranch1
eb7b3000..67f0ade3 mybranch2 -> origin/mybranch2
eb7b3000..67f0ade3 mybranch3 -> origin/mybranch3
...and usually also some [new tag] lines
This identifies the branches that have been updated by the "first" local repo, and I proceed to update each one by one, like this...
$ git fetch origin mybranch1:mybranch1
$ git fetch origin mybranch2:mybranch2
$ git fetch origin mybranch3:mybranch3
This is a slightly painful manual procedure but it works perfectly. Seems that "git fetch --all" or something like that should do this, maybe I'm missing the obvious here, but I can't seem to find a built-in git command that updates those other branches without checking them out. The mybranch1:mybranch1 syntax as above seems to do it perfectly, leaving me wherever I was, but ensuring that a reloaded gitk will now show correct info for all the remote branches, which have been updated by this sequence of fetches.
I have looked at the bash and one-liner solutions to similar but different problems eg here: [How to fetch all Git branches
These solutions identify all branches, and solve a slightly different problem. I want to just fetch and update local branches that are tracking a repo branch if that has changed, not grab all branches including ones I am not tracking locally.
I'm struggling to write the alias or bash script (or expose the 'obvious' trick I may have missed) to solve this. I just want to be able to type a single alias or other command that does the git fetch, identifies all the branches that have been updated and then does that sequence of git fetch origin aaa:aaa etc for each changed remote branch. Any help appreciated.
[Currently using git cmd line version 2.17.1.windows.2, happy to update if that's the problem]