-2

git push -u can set up tracking relation between an upstream branch and a local tracking branch, see Why does this example use `git push` without `-u`, while another example does?

Can git fetch also set up tracking relation between an upstream branch and a remote tracking branch, as defined in remote.<remote>.fetch, possibly by some option?

Can git pull set up either or both of the tracking relation between an upstream branch and a remote tracking branch, and the tracking relation between an upstream branch and a local tracking branch, possibly by some option?

halfer
  • 19,471
  • 17
  • 87
  • 173
Tim
  • 88,294
  • 128
  • 338
  • 543

1 Answers1

1

No, apparently it cannot: the obvious git fetch origin <branch_name>:<branch_name>, which fetches origin/<branch_name> and updates <branch_name> to point to it, does not create the tracking relationship if it does not already exist.

This is how I usually create the tracking relationship:

git fetch origin <branch_name>
git checkout <branch_name>

If the local branch does not already exist when you do the checkout, it will be created as a tracking branch.

This command creates the branch without checking it out:

git branch -u <branch_name> origin/<branch_name>
joanis
  • 6,977
  • 11
  • 26
  • 33