0

I'm new to git and when I'm at work I would first branch off from the master branch and then start working, after finishing the work and then add and commit, after all of these I tried to push but sometimes I got the following message (sometimes not):

fatal: The current branch ql/live+my_branch has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin ql/live+my_branch

I know the problem will be solved by the above command but I was thinking when I branch off from the master branch then the master branch becomes the upstream branch of the current branch, why would I have to set it again? thanks in advance!

photosynthesis
  • 2,632
  • 7
  • 29
  • 45
  • 2
    http://stackoverflow.com/a/17096880/6309 could help. – VonC Jul 28 '14 at 19:00
  • 1
    Note that, by "upstream branch", Git refers, not to your local `master` branch, but to a branch that resides on the remote repo you're trying to push to. – jub0bs Jul 28 '14 at 19:00
  • Or this as well http://stackoverflow.com/questions/6089294/why-do-i-need-to-do-set-upstream-all-the-time. By the way, it was the first result googling for `git upstream branch` so I am forced to mark as duplicate. – ThanksForAllTheFish Jul 28 '14 at 19:13

1 Answers1

1

I may have misunderstood your question but I believe this may answer you. Your local repo doesn't necessarily mirror that of your remote repo. The remote repo has by default a master branch, however the local branches you create to do your work on are not going to be tracked in the remote repo unless you tell it to. Therefore, if you are working on a local branch you have to set the upstream so that when you push the branch will be created remotely too. If you do not set the upstream then git will push your commit onto the remote master as if you had done the work on master.

If you tend to work on local branches, merge into master and then push, you may consider using the no fast forward (git merge my_branch --no-ff) in order to retain the commit history remotely when you push master.

JColl
  • 51
  • 3
  • you absolutely understand my question right, thanks for the explanation. I was thinking the upstream branch is set up automatically by git when branch off from the master, but it turns out is not the default behavior. – photosynthesis Jul 28 '14 at 19:14