将分支推送到 Git

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1072261/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 06:40:38  来源:igfitidea点击:

Push branches to Git

gitbranchgithubgit-pushgit-pull

提问by PHLAK

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.

我有一个正在处理的本地存储库,它的远程存储库托管在 GitHub 上。我最近创建了一个分支并开始处理它,进行了几次提交,现在希望将该分支推送到 GitHub 并能够将其拉到另一个克隆的存储库中。

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.

如果使用 GitHub 无法做到这一点,我很高兴知道如何正常进行。

回答by Alan Haggai Alavi

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.

代替<local-branch-name><remote-branch-name>。它们可能相同或不同,随您的需要。

回答by J-16 SDiZ

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 originwould push all branches with the matching name on remote.

之后, usinggit push origin会将所有具有匹配名称的分支推送到远程。

回答by mturquette

Make sure that your remote URL is using SSH syntax and not just Git protocol syntax. If you run,

确保您的远程 URL 使用 SSH 语法,而不仅仅是 Git 协议语法。如果你跑,

git remote show origin

the URL printed should look something like,

打印的 URL 应该类似于,

[email protected]: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,

如果您希望能够推送,您也需要 URL 看起来像这样。如果您只是一个公共用户(没有写访问权限),则 URL 将如下所示,

git://github.com/yourname/projectname.git

If yours looks like the latter then you can manually edit it in your projects .git/configfile.

如果你的看起来像后者,那么你可以在你的项目.git/config文件中手动编辑它。

回答by Rizo

if you need to pull any branch code from remotely to locally

如果您需要从远程拉取任何分支代码到本地

$git pull origin branch_name

while if you need to push code to your branch

而如果您需要将代码推送到您的分支

you need to check is your code successfully save you can check by

您需要检查您的代码是否成功保存您可以检查

$git status

than

$git add -A

after this make commit to your branch

在此之后提交到​​您的分支

$git commit -m "this is initial change"

than(Last) push your code to your branch by:

than(Last) 通过以下方式 将您的代码推送到您的分支:

$git push origin branch_name