您的位置:首页 > 其它

How to Push a New Local Branch to a Remote Git Repository

2013-06-09 13:20 375 查看
You might find yourself in a situation where you have a branch that you created locally and want to push to a remote git repository. Suppose you created a local
plugin branch that you want to expose to others through your GitHub repository but you are not yet confident enough to put it into the master branch. Here is the command you would execute to push all of the changes from your
plugin branch to a plugin branch on the GitHub repository:

1
git push -u origin plugin
This tells git to push changes from your plugin branch to the plugin branch on the
origin repository. If origin does not have a plugin branch, it is created on the fly. The
-u tells git that you want to be able to easily push and pull changes to that branch in the future.

Now, say your friend Bob wants to access the hot new feature you just pushed to the new branch on the GitHub repository. All Bob needs to do is update his local repository with all of the changes on the GitHub repository and create a local branch where he
can play with the new code.

1
git fetch origin
2
git checkout --track origin/plugin
The first command updates Bob's repository with the changes from the remote repository. The second command creates a local branch named
plugin that matches the origin/plugin branch and tells git that Bob wants to be able to easily push and pull from the branch on GitHub. Bob can now play with the code, commit his own changes and
git push them back up to the GitHub repository.
UPDATE: As Andy mentioned, you probably want to set the upstream so you can easily interact with the remote branch in the future. Hence, I added -u to the original git push example.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: