Push and pull branches in Git
I have a local repository I'm working on and its remote is hosted on GitHub. I recently created a branch and started working on it, making several commits and now wish to push the branch to GitHub and be able to pull it to another cloned repository.
What needs to be done to accomplish this?
If this is not possible using GitHub, I'd be happy to know how to do it normally.
git push origin <local-branch-name>:<remote-branch-name>
Substitute for <local-branch-name>
and <remote-branch-name>
. They may be same or different, as you wish.
As you have set up the remotes already, the command is just
git push origin branch-name
on the first push.
Afterward, using git push origin
would push all branches with the matching name on remote.
Make sure that your remote URL is using SSH syntax and not just Git protocol syntax. If you run,
git remote show origin
the URL printed should look something like,
git@github.com:yourname/projectname.git
You need the URL too to look like that if you want to be able to push. If you are just a public user (without write access) the URL will look like,
git://github.com/yourname/projectname.git
If yours looks like the latter then you can manually edit it in your projects .git/config
file.
上一篇: 为每个部署构建在git中制作标记是否是一个好习惯?
下一篇: 在Git中推拉分支