14

I'm trying to track an exiting branch to a remote branch using --track or --set-upstream-to, but got the following error

$ git branch --track master origin/master
fatal: A branch named 'master' already exists.   
$ git branch --set-upstream-to master origin/master
fatal: branch 'origin/master' does not exist   

I checked SourceTree and found that it uses --set-upstream, but got the following warning

$ git branch --set-upstream master origin/master
The --set-upstream flag is deprecated and will be removed. Consider using --track or --set-upstream-to
Branch master set up to track remote branch master from origin.

Both --track and --set-upstream-to is not working, Am I missing something?

BJ Myers
  • 6,617
  • 6
  • 34
  • 50
Mahmoud Adam
  • 5,772
  • 5
  • 41
  • 62
  • 1
    Did you try `--set-upstream-to`? In your question you only mention `--set-upstream`. Also note that you can accomplish the same thing with the `-u` flag to `git push` (`git push -u origin master`). – larsks Feb 12 '14 at 13:42
  • For that matter, the `--set-upstream` actually *worked*. It just first printed a warning: "this old variant is going away, modify your code and/or habits to use the new variant, `--set-upstream-to`". (The `--set-upstream-to` version takes the parameters in the other order, allowing it to default to "set current branch" like other `git branch` commands.) – torek Feb 12 '14 at 23:31
  • For what it's worth, [here is the documentation for `git branch`](https://www.kernel.org/pub/software/scm/git/docs/git-branch.html). –  May 23 '14 at 18:10
  • Duplicate of [How do you make an existing Git branch track a remote branch?](http://stackoverflow.com/questions/520650/how-do-you-make-an-existing-git-branch-track-a-remote-branch) –  May 23 '14 at 18:26

1 Answers1

24

I think I got it, it will be as the following (used --set-upstream-to + remote name)

$ git branch --set-upstream-to origin/master
Branch master set up to track remote branch master from origin.
Mahmoud Adam
  • 5,772
  • 5
  • 41
  • 62