githubteacher / github-for-developers-sept-2015

practice repo for the Sept 29-30 GitHub for Developers class
12 stars 36 forks source link

Push conflict (push -u v/s push) #686

Closed vb186017 closed 9 years ago

vb186017 commented 9 years ago

I think my push command lead to push conflict. Here are the steps I followed:

  1. Cloned master
  2. Created new branch (B1) locally
  3. Switched to B1 and made changes
  4. Used "git push -u origin B1"
  5. From github.com, merged the branch after creating pull request and deleted it
  6. Locally, made some more changes to B1
  7. Used "git push" (Thinking it will not make a push to master)

Can you please provide more explanation on this?

nickomart commented 9 years ago

:+1:

jaw6 commented 9 years ago

@vb186017 So, -u is short for --set-upstream -- it creates a link between your local branch and the remote branch you are pushing to, so in the future, git pull and git push (without any other parameters) will, by default, continue to pull/push from the remote branch specified.

In this case, git push -u origin B1 is saying "push branch B1 to the remote origin using the same B1 name in both places and make it so that future push/pull commands on B1 (or pulls) also go to origin/B1"

vb186017 commented 9 years ago

So basically my second "git push" ideally pushed to master?

jaw6 commented 9 years ago

So basically my second "git push" ideally pushed to master?

If you were following the steps you describe here, and were checked-out to B1 when you did a git push, you pushed to B1, not to master.