What's the Difference Between "git push --set-upstream" and "git branch --set-upstream-to"?

"git push --set-upstream" vs. "git branch --set-upstream-to"

git branch --set-upstream-to

By using this command you can make an existing local branch track a specified remote branch. For example:

git branch --set-upstream-to remote_name/branch_name

git push --set-upstream

By using this command you can setup tracking information for the current branch during the push. For example:

git push --set-upstream remote_name remote_branch_name

This may especially be useful in case where you created a new branch on your local that has no upstream branch setup. For example:

# create new local branch
git checkout -b new_local_branch

# stage all files in the current directory
git add .

# commit staged files
git commit

# fatal: The current branch new_local_branch has no upstream branch.
git push

In such a case, to push the current branch and set the remote as upstream, it would make sense to use git push command with the --set-upstream option.

Hope you found this post useful. It was published . Please show your love and support by sharing this post.