![]() So do we really need to repeat ourselves? Even if it’s only one time, when we try to push a new branch, it’s still distractive. # create new branchīut in most workflows, we will always want to have the remote branch named exactly the same as the local one. Upstream will be shown in square brackets and blue font. We can check it with git branch -vv command. Since then Git will know that the “upstream” branch for our local one is an origin/feature-1. So we need to copy or write this longer version of the command, suggested in the error message. Git suspects that we want to push to default remote, called origin, and name the remote branch exactly the same as a local one. This means that Git doesn’t know to which remote repository it should push our branch, and how this branch should be named on that remote repository. To push the current branch and set the remote as upstream, use $ git pushįatal: The current branch feature-1 has no upstream branch. The name of your current branch.When we create a new branch and try to push it with simple git push command, Git rejects it with a “no upstream branch” error. ![]() the remote branch *must* have the same name as local.įatal: The upstream branch of your current branch does not match # this is similar to "current" and unlike "upstream". ![]() # try pushing - and note that again it fails. # switch to the testing2 and set nottesting2 as its upstream # create a new branch locally and push to remote # this behaviour is similar to "upstream" and unlike "current". # try pushing this branch to the remote end - note that it fails. Thus simple is a cross between current and upstream – unlike current it does not create a new branch and unlike upstream it cannot push to a branch with a different name. However, if a branch of the same name doesn’t exist at the remote end, a new one won’t be created. simple: If you don’t specify the remote, push the current branch to a branch with the same name on the remote end.This GitHub help page too is worth a read. These in turn helped me understand why the push policy is called upstream and the scenarios where one might require such a policy. If that’s the behavior you want, be sure to set the push policy as upstream.Īs an aside: I found this and this – two useful posts from StackOverflow to understand the concept of an upstream remote. This makes it impossible to have your local branch point to a differently named remote branch and issue git push without any further instructions and expect it to work. If the push policy is set to current it always pushes to a branch of the same name on the remote end, and if such a branch doesn’t exist it creates one. The last example makes the difference between current and upstream very clear. # just to compare "matching" with "current" let's change the push policy to "current" and see what happens # and do a git push with no remote specified and notice how it works without a fuss!Įnter passphrase for key '/c/Users/rakhesh/.ssh/id_rsa': # now switch to testing2 and set nottesting2 as its upstreamīranch testing2 set up to track remote branch nottesting2 from origin. # let's create a new branch called nottesting2 and set that as the upstream Hint: "git push -u" to set the upstream config as you push. Hint: will track its remote counterpart, you may want to use Hint: If you are planning to push out a new local branch that ![]() Hint: branch that already exists at the remote, you may need to Hint: If you are planning on basing your work on an upstream PS> git branch -set-upstream-to origin/testing2Įrror: the requested upstream branch 'origin/testing2' does not exist # set the upstream via git branch - note that it fails as the remote branch does not exist # delete the remote branch so I can try one more thing # if the remote branch name is explicitly specified, a new branch is created and pushed to # try pushing this branch to the remote end - note that it failsįatal: The current branch testing2 has no upstream branch. # create a new branch called testing2 and switch to it
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |