0

We have tools that use history data from master to determine what files are available to download. When using "git pull", the fetch part of that command gets the history of master and thus everything works fine. However, git pull (remote) (branch) only fetches that branch, which sometimes breaks our tools. Is there a way configure git pull (remote) (branch) to also fetch one or all other branches instead of just that branch?

user2460953
  • 319
  • 1
  • 3
  • 10
  • This sounds *ridiculously* undesirable, but given that Git is Git, it's possible. Would this answer your question? [How to fetch all Git branches](https://stackoverflow.com/questions/10312521/how-to-fetch-all-git-branches) – Makoto Apr 28 '20 at 17:34
  • Sorry, I didn't mean all branches on the remote, I meant pulling the same branches as "git pull" would. Or is that the same thing? – user2460953 Apr 28 '20 at 17:41
  • Pulling branches *only* has meaning in the context of remote. If you have no remote branches, you have no reason to pull anything since all of it is already there. – Makoto Apr 28 '20 at 17:56
  • right, essentially we could right a script to do "git fetch & git pull origin mybranch", and I was hoping to be able to configure git to do that fetch by default when you run "git pull origin mybranch" – user2460953 Apr 28 '20 at 18:09

1 Answers1

0

You literally can't do what you're asking for: git pull origin name fetches only the one branch by design. But it doesn't matter: git pull is a bad tool and you should just not use it.

All git pull does is run git fetch first, followed by git merge or git rebase second. Since you have your own tools, just code them to run git fetch first followed by your chosen second Git command second. You now control how you run git fetch, so you can choose to fetch both master and one particular branch, or all branches (the default). Then you run the second command that git fetch would have run: if you were going to do:

git pull origin mybranch

you just run instead:

git fetch origin && git merge origin/mybranch

(assuming you don't mind the minor difference around the default merge message), or:

git fetch origin && git rebase origin/mybranch

if you prefer git rebase as the second command.

torek
  • 448,244
  • 59
  • 642
  • 775
  • So if it were me personally, I would just script it. However, I am looking to help everyone in my organization. We are just starting out with git and users keep stumbling into this my mistake as no one knows that "git pull origin name" is not enough. Is there a way we can restrict what users can do by default? The heavy hammer option is to tell everyone to not run git directly and to use a wrapper script. Is that the best way to do things? – user2460953 Apr 29 '20 at 02:12
  • @user2460953: Given newbies and the fact that you do have a wrapper script, that's probably how I'd go (i.e., tell everyone: use the provided wrapper unless you really know what you're doing). – torek Apr 29 '20 at 06:49