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:
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.
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.
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 |
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 |
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.
相关文章推荐
- Moving git repository and all its branches, tags to a new remote repository keeping commits history
- How to delete the remote branch in git
- how to remote push repository to github--解决403forbidden和publickey问题
- Git: How to revert a merge commit that's already pushed to remote branch?
- git push错误 remote: error: refusing to update checked out branch: refs/heads/master 解决方式
- [Git] How to rename your remote branch
- how to clone a git repository to local
- Git HowTo: revert a commit already pushed to a remote repository
- How to push master to QA branch in GIT
- Push local non-git project to remote github repo
- [Git]setting an existed local branch to track a remote branch
- X-code7 Git 时push错误 The local repository is out of date.
- remote: Permission to repository_name.git denied to xxxx.
- git push error:error: insufficient permission for adding an object to repository data
- how to mount remote disk as local disk
- How can I recover a file that I deleted in my local repo from the remote repo in Git?
- git push origin master fatal: 'origin' does not appear to be a git repository fatal: Could not read
- how to mount remote disk as local disk at startup
- How To Create A Local Repository For SUSE Linux
- How To Create A Local Repository For SUSE Linux