本文介绍了我怎样才能从原始回购的克隆中推到我的分支?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在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



然后


  • 生成的克隆的本地配置只列出一个名为 origin 的远程,它与您克隆的存储库的URL相关联;

  • 克隆中的本地 master 分支设置为 track origin / master


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

      git push 

    as



    pre $ git push origin master:origin / master

    换句话说, git push 尝试将本地 master 分支推送到 master 分支驻留在远程存储库(由您的克隆已知为 origin )。但是,您不允许这样做,因为您无权访问该远程存储库。



    您需要


    1. 通过运行

      $ b,重新定义与您的分支关联的 origin remote。
      $ b

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


    2. 或者,如果您想保留 origin 远程的原始定义,请定义一个新的远程(在这里称为 myrepo ,在这里)与您的fork相关联:

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

      然后您应该通过运行

       能够将本地 master  git push myrepo master 

      如果你想告诉Git git push 应该从现在开始推送至 myrepo 而不是 origin ,你笑uld run

        git 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 track origin/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

    1. either redefine the origin remote to be associated with your fork, by running

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

    2. 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
      

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

      git push myrepo master
      

      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
      

    instead.

    这篇关于我怎样才能从原始回购的克隆中推到我的分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 19:59