Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从GitHub克隆项目,但将Bitbucket用作远程存储库_Git_Github_Bitbucket - Fatal编程技术网

如何从GitHub克隆项目,但将Bitbucket用作远程存储库

如何从GitHub克隆项目,但将Bitbucket用作远程存储库,git,github,bitbucket,Git,Github,Bitbucket,我想从GitHub克隆一个开源项目,但我想使用Bitbucket作为远程存储库主机,因为它的私有repo是免费的 我不打算fork/pull请求,但当原始项目得到更新时,我希望将更新拉到本地存储库并合并 我认为最终我将需要两个远程存储库。(起点和上游?) 设置这种环境的正确/最安全的方法是什么?我刚刚在GitHub上用我的一个项目测试了它: 首先,我登录了我的Bitbucket帐户,创建了一个名为谷歌日历备份的私有Git repo 然后,我做了以下步骤: (注意:我在Windows上,因此您的计

我想从GitHub克隆一个开源项目,但我想使用Bitbucket作为远程存储库主机,因为它的私有repo是免费的

我不打算fork/pull请求,但当原始项目得到更新时,我希望将更新拉到本地存储库并合并

我认为最终我将需要两个远程存储库。(起点和上游?)


设置这种环境的正确/最安全的方法是什么?

我刚刚在GitHub上用我的一个项目测试了它:

首先,我登录了我的Bitbucket帐户,创建了一个名为
谷歌日历备份
的私有Git repo

然后,我做了以下步骤:
(注意:我在Windows上,因此您的计算机上的路径可能不同)

  • 从GitHub克隆原始repo

    git clone https://github.com/christianspecht/google-calendar-backup C:\LocalDir
    
  • 这将在本地回购中创建一个指向GitHub的远程“来源”。
    由于您希望主要使用Bitbucket,因此Bitbucket应该是“主”远程
    来源,因此我们将重命名现有的一个

    cd c:\localdir
    git remote rename origin upstream
    
  • 转到本地目录并将Bitbucket repo添加为第二个远程:

    git remote add origin https://bitbucket.org/christianspecht/google-calendar-backup
    
  • (可选)显示两个遥控器:

    git remote -v
    
    在我的机器上,我得到以下结果:

    origin  https://bitbucket.org/christianspecht/google-calendar-backup (fetch)
    origin  https://bitbucket.org/christianspecht/google-calendar-backup (push)
    upstream        https://github.com/christianspecht/google-calendar-backup (fetch)
    upstream        https://github.com/christianspecht/google-calendar-backup (push)
    
  • 将所有分支推送到Bitbucket一次

    git push -u --all origin
    
    结果:

    Username for 'https://bitbucket.org': christianspecht
    Password for 'https://christianspecht@bitbucket.org':
    Counting objects: 30, done.
    Delta compression using up to 4 threads.
    Compressing objects: 100% (30/30), done.
    Writing objects: 100% (30/30), 4.41 KiB | 0 bytes/s, done.
    Total 30 (delta 12), reused 0 (delta 0)
    To https://bitbucket.org/christianspecht/google-calendar-backup
     * [new branch]      master -> master
    Branch master set up to track remote branch master from origin.
    
    (感谢
    -u
    -我不知道这一点,我自己还在学习Git)


  • 就这样。现在,您可以进行更改并推送到
    源站
    (Bitbucket)。

    有时,您需要从
    上游
    (GitHub)获取原始项目的新更改。

    我认为您已经描述了一个合适的解决方案。您将需要两个遥控器,一个指向gitub,另一个指向bitbucket。对于这种设置,
    origin
    upstream
    的名称非常典型。第一次按下分支时,请确保使用
    -u
    设置正确的远程跟踪分支。谢谢,知道我的方向是正确的真是太好了。我只知道git的基本命令,从未尝试过这个级别的任何东西。我读过很多博客和文章,但找不到完全相同的情况。谢谢,它工作得很好。我还需要以同样的方式设置另一台计算机。但由于我已经将代码推送到了Bitbucket respository,我正在考虑克隆这个代码,而不是在Github上的原始代码,然后向Github repo添加一个上游分支。我明天试试。