Set the upstream branch for an existing branch in git

April 20, 2021  ‐ 1 min read

Probably the most convenient way to set an upstream branch is to do so when you push the branch. You do so by adding the -u option to the push command, with -u being the short option for --set-upstream.

$ git push -u <remote> <branch>

For an existing branch you might want to set the upstream branch without having to push at the same time. You can set the upstream branch as well using the command:

$ git branch (--set-upstream-to=<upstream> | -u <upstream>) [<branchname>]

In practice that would look like the following:

$ git branch -u origin/dev