
Initialized empty Git repository in F:/Sandbox/gitdemo/test/.git/ Say, I have created a new repository and added its origin $ git init test # create a new empty repo Remote branch information is retrieved from its upstream. When these commands are used without any conditional arguments, Setting upstream has effect on many commands e.g. Here master branch is tracking origin/master. Used to print the remote tracking branch. Local branch A and its upstream is set to origin/B, then every push will push the changes to origin/B etc. Every local branch has exactly one upstream set. Upstream is the name of remote branch to which our local branch is synced. To push the current branch and set the remote as upstream, useĮnough is enough, I have searched about it and I am going to write about it. fatal: The current branch master has no upstream branch. You just have to be careful.ĮDIT: sorry, it is deprecated in commit b347d06bf097aca5effd07871adf4d0c8a7c55bd, but these commits only mention git-branch, not git-push.Whenever I push my newly created local repository to a remote repo, I am prompted with this message. I don't know if it was deprecated more recently, but the fact the the git-branch(1) manpage for git-2.7.5 mentions it without warning about it, means it's still around and is going to stay around. I would say it's not quite deprecated but it is discouraged. To set the current branch's upstream to be origin's master. Git branch -set-upstream-to origin/master Should be and one optinal argument indicating which branch to change, To work around this, introduce -set-upstream-to whichĪccepts a compulsory argument indicating what the new upstream branch As -set-upstream already exists, we can't simply change itsīehaviour. To create a new local branch 'origin/master' that tracks the currentīranch. Usual branch convention of assuming a starting point of HEAD if none The existing -set-uptream option can cause confusion, as it uses the Any version more recent than that should include it. set-upstream-to was introduced in 2012 in the 1.7.12-1.7.13 timeframe. It's related to git branch -set-upstream-to, but not the same. And now you can use git branch -set-upstream-to, but it might be nice if git push could do that automatically-and that's the git push -set-upstream, aka -u, option.

Now that they do have a newbranch, your Git creates your origin/newbranch to remember their newbranch. Soon, however, you git push your local newbranch to their Git, so that their Git creates newbranch in their repository. But if you try, it fails: $ git branch -set-upstream-to=origin/newbranchĮrror: the requested upstream branch 'origin/newbranch' does not existīecause origin/newbranch does not exist yet, because the other git at origin does not have a branch named newbranch.

That is, suppose you have created a branch newbranch: $ git checkout -b newbranchĪnd want to set its upstream to origin/newbranch. It means that if the push succeeds, your local Git should set, as the upstream of a branch reference supplied as your source, the remote-tracking branch corresponding to the destination branch you got the other Git to set, which in many cases, your own Git has just now created in your repository because their Git has also just created their branch. The git push command has only -u aka -set-upstream, which takes no argument.

The git branch command has both -set-upstream and -set-upstream-to, with the former deprecated in favor of the latter for the reason already given in Nick's answer.
