Difference between git branch --set-upstream-to vs git remote add origin

In order to set the remote tracking branch with set-upstream-to, you need to define a remote repo.

When your developers are cloning the bare repo, a remote named origin is automatically defined for them. I.e, on each local clone, a git remote -v would list a remote repo named origin, referencing the bare repo. They don't need to define a remote named upstream.

However, that doesn't mean all the branches from that remote are tracked by a local branch.
That is where git branch --set-upstream-to can come into play.


git remote add creates a remote, which is a shorthand name for another repository. git branch --set-upstream-to sets a branch to be tracked by the branch in the remote repository specified.

What you are wanting to do is track a remote branch, which is done with git branch --set-upstream-to or more simply git branch -u.

when you clone a repository from another, a remote is created named origin and the branch master is checked out. The command to have your local branch master track the remote branch master is git branch -u origin/master, and is executed from the local master branch.