简体   繁体   中英

GitHub 'push branch to server' button does what?

I pulled down the master branch of one of our GitHub repos (did not fork it) and branched from the command line, did some work, added + committed and then rebased master.

When I called git push from the command line I got a message stating The current branch has no upstream branch. To push the current branch and set the remote as upstream, use git push --set-upstream origin my_branch. The current branch has no upstream branch. To push the current branch and set the remote as upstream, use git push --set-upstream origin my_branch.

Well, I saw the mention in there of 'origin' and was a little worried this would somehow push my changes to master and not my_branch . I'm new to GitHub and thought I should play it safe.

Instead, I opened the GitHub for windows client, found my branch in there and clicked the 'push branch to server' button. (At least I think that's what it said.) Lo and behold, it worked.

What did clicking that button do behind the scenes, so I know which commands to run the next time through?

It basically did:

git checkout my_branch
git push origin my_branch

If you do

git push --set-upstream origin my_branch

Everytime you are in the branch, all you will need to do is run:

git push

And it will automatically go to my_branch branch on Github.

Probably something like the command mentioned - git push origin my_branch .

The message The current branch has no upstream branch. means that Git cannot find a remote branch associated with your newly created branch (that makes sense, there's no such branch in the remote repository).

git push --set-upstream origin my_branch means "take the local my_branch, find my_branch in origin and upload the changes there. Also set origin/my_branch as the default branch for git push in my_branch". So the next time, with my_branch checked out, you simply git push and the changes are uploaded to the appropriate remote branch.

man git push has some good and demonstrative examples (as well as other git commands).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM