问题描述
我在GitHub上创建了另一个仓库(我们称之为 orirepo
)的一个分支(让我们称之为 myrepo
) 。后来,我克隆了 orirepo
。
git clone https:// github .com / original / orirepo.git
我修改了大约20个文件, a commit
git add
git commit
然而,当我试图推送
git push
我得到这个错误:
remote:原始/ orirepo.git被拒绝给mylogin的权限。
致命:无法访问'https://github.com/original/orirepo.git/':请求的URL返回错误:403
我知道我犯了一个错误:我应该克隆我的分支,而不是 orirepo
,但现在已经太晚了。
我如何推送到我的分支,而不是 origin / orirepo
,我没有写权限?
- ,它位于
https://github.com/original/orirepo.git
, - ,其当前分支名为
master
,
然后 因此,如果您不修改克隆的配置,Git会解释
origin
的远程,它与您克隆的存储库的URL相关联;
master
分支设置为 track origin / master
。
git push
as
pre $
git push origin master:origin / master
换句话说, git push
尝试将本地 master
分支推送到 master
分支驻留在远程存储库(由您的克隆已知为 origin
)。但是,您不允许这样做,因为您无权访问该远程存储库。
您需要
-
通过运行
$ b,重新定义与您的分支关联的origin
remote。
$ bgit remote set-url origin https://github.com/RemiB/myrepo.git
-
或者,如果您想保留
origin
远程的原始定义,请定义一个新的远程(在这里称为myrepo
,在这里)与您的fork相关联:
git remote add myrepo https://github.com/RemiB/myrepo.git
然后您应该通过运行
能够将本地
master
git push myrepo master
如果你想告诉Git
git push
应该从现在开始推送至myrepo
而不是origin
,你笑uld rungit push -u myrepo master
代替。
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
I modified about 20 files, then I staged my change and made a commit
git add
git commit
However, when I tried to push
git push
I got this error:
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
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
- that resides at
https://github.com/original/orirepo.git
, - whose current branch is called
master
,
then
- 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 trackorigin/master
.
Therefore, if you don't modify the config of your clone, Git interprets
git push
as
git push origin master:origin/master
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.
You need to
either redefine the
origin
remote to be associated with your fork, by runninggit remote set-url origin https://github.com/RemiB/myrepo.git
or, if you want to preserve the original definition of the
origin
remote, define a new remote (calledmyrepo
, here) that is associated to your fork:git remote add myrepo https://github.com/RemiB/myrepo.git
Then you should be able to push your local
master
branch to your fork by runninggit push myrepo master
And if you want to tell Git that
git push
should push tomyrepo
instead oforigin
from now on, you should rungit push -u myrepo master
instead.
这篇关于我怎样才能从原始回购的克隆中推到我的分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!