1

I have a local branch which I want to link to a remote branch. So when I do git pull it will auto use linked remote branch

I tried to use git branch --track origin/branchname but it did a weird thing and created kind of a tag with name origin/branchname And git pull still didn't auto select linked branch

on other hand git branch -u origin/branchname did work and git pull autoselects correct branch

what is the diff with --track and -u ?

VextoR
  • 5,087
  • 22
  • 74
  • 109

1 Answers1

1

The git branch command does (in my opinion, anyway) too many different things.

In particular, you can ask it to create a branch—a new branch name, that is; see What exactly do we mean by "branch"?—with various settings for that new name.

You can also ask it to modify an existing branch, which is what you wanted to do. The -u or --set-upstream-to option does this.

The --track option is for creating a new branch:

I tried to use git branch --track origin/branchnamebut it did a weird thing and created kind of a tag with name origin/branchname

More specifically, it created a local branch named origin/branchname. Normally any time you see origin/foo, origin/master, origin/whatever, these are remote-tracking branches (see the linked question). Creating a local branch with such a name just sets things up to be confusing. (Git won't have any trouble with it, it's just confusing for humans. :-) )

Community
  • 1
  • 1
torek
  • 448,244
  • 59
  • 642
  • 775