如何从原始存储库的克隆推送到我的分叉? [英] How can I push to my fork from a clone of the original repo?

查看:29
本文介绍了如何从原始存储库的克隆推送到我的分叉?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 GitHub 上创建了另一个存储库(我们称之为 orirepo)的分支(我们称之为 myrepo).后来,我克隆了orirepo.

I created a fork (let's call it myrepo) of another repository (let's call it orirepo) on GitHub. Later, I cloned orirepo.

git clone https://github.com/original/orirepo.git

我修改了大约 20 个文件,然后我进行了更改并提交了

I modified about 20 files, then I staged my change and made a commit

git add
git commit

然而,当我试图推动

git push

我收到此错误:

remote: Permission to original/orirepo.git denied to mylogin.
fatal: unable to access 'https://github.com/original/orirepo.git/': The requested URL returned error: 403

我知道我犯了一个错误:我应该克隆我的叉子而不是 orirepo,但现在为时已晚.我如何才能推送到我的 fork 而不是 origin/orirepo,我没有写入权限?

I know I made a mistake: I should have cloned my fork rather than orirepo, but it's too late for that now. How could I push to my fork rather than to origin/orirepo, which I don't have write access to?

推荐答案

默认情况下,当你克隆一个仓库时

By default, when you clone a repository

  • 位于 https://github.com/original/orirepo.git
  • 其当前分支名为master,

然后

  • 生成的克隆的本地配置仅列出了一个名为 origin 的远程,它与您克隆的存储库的 URL 相关联;
  • 克隆中的本地 master 分支设置为 track origin/master.
  • the local config of the resulting clone lists only one remote called origin, which is associated with the URL of the repository you cloned;
  • the local master branch in your clone is set to track origin/master.

因此,如果您不修改克隆的配置,Git 会解释

Therefore, if you don't modify the config of your clone, Git interprets

git push

作为

git push origin master:origin/master

换句话说,git push 尝试将您的本地 master 分支推送到驻留在远程存储库上的 master 分支(由您的克隆为 origin).但是,您不能这样做,因为您没有对该远程存储库的写访问权限.

In other words, git push attempts to push your local master branch to the master branch that resides on the remote repository (known by your clone as origin). However, you're not allowed to do that, because you don't have write access to that remote repository.

你需要

  1. 要么通过运行重新定义 origin 远程与您的叉相关联

git remote set-url origin https://github.com/RemiB/myrepo.git

  • 或者,如果您想保留 origin 遥控器的原始定义,请定义一个新的遥控器(此处称为 myrepo)与您的叉子:

  • or, if you want to preserve the original definition of the origin remote, define a new remote (called myrepo, here) that is associated to your fork:

    git remote add myrepo https://github.com/RemiB/myrepo.git
    

    然后你应该能够通过运行将你的本地 master 分支推送到你的分支

    Then you should be able to push your local master branch to your fork by running

    git push myrepo master
    

    如果你想告诉 Git 从现在开始 git push 应该推送到 myrepo 而不是 origin,你应该运行>

    And if you want to tell Git that git push should push to myrepo instead of origin from now on, you should run

    git push -u myrepo master
    

  • 相反.

    这篇关于如何从原始存储库的克隆推送到我的分叉?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆