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

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:
1git 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.

1git fetch origin
2git 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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值