将分支推送到 Git

发布于 2024-07-26 19:24:49 字数 112 浏览 7 评论 0原文

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

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. How do I do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

香草可樂 2024-08-02 19:24:49
git push origin <local-branch-name>:<remote-branch-name>

替换 。 它们可以相同也可以不同,如您所愿。

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.

泛泛之交 2024-08-02 19:24:49

由于您已经设置了遥控器,因此该命令仅

git push origin branch-name

在第一次按下时发出。

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

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.

风追烟花雨 2024-08-02 19:24:49

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

git remote show origin

打印的 URL 应该看起来像这样,

[email protected]:yourname/projectname.git

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

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

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

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,

[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,

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

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

凤舞天涯 2024-08-02 19:24:49

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

$git pull origin branch_name

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

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

$git status

$git add -A

在此提交到您的分支之后

$git commit -m "this is initial change"

比(最后)
通过以下方式将代码推送到分支:

$git push origin branch_name

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:

$git push origin branch_name
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文