将现有的GitHub存储库分叉到Bitbucket

时间:2019-01-09 10:11:38

标签: git github bitbucket

我很难将现有的GitHub存储库分叉到Bitbucket。我使用了终端来使用git远程添加,如指导中所述,但是它一直在报告fatal: the remote origin already exists。同样,当我尝试推动它时,什么也没发生。我已经查看了此处更改名称的答案,但是我一直在使用GitHub链接,但没有任何反应。我不知道我是否正确地将我的fork远程来源和原始回购称为上游。还有其他人遇到过类似的问题吗?我对这是如何工作还很陌生,仍然在学习。

git remote add
git remote rm
git push -u origin

$ git init
Reinitialized existing Git repository in /Users/appleuser/Desktop/axios-react/.git/

$ git remote add origin https://XXX@bitbucket.org/crowddoingmedicinalfoods/react.git

$ git push -u origin master
remote: Forbidden
fatal: unable to access 'https://XXX@bitbucket.org/crowddoingmedicinalfoods/react.git/': The requested URL returned error: 403

$ git clone https://github.com/ItsAntP/axios-react-github.git
Cloning into 'axios-react-github'...
remote: Enumerating objects: 27, done.
remote: Counting objects: 100% (27/27), done.
remote: Compressing objects: 100% (21/21), done.
remote: Total 27 (delta 5), reused 27 (delta 5), pack-reused 0
Unpacking objects: 100% (27/27), done.

$ git remote -v
another_origin  https://github.com/ItsAntP/axios-react-github.git (fetch)
another_origin  https://github.com/ItsAntP/axios-react-github.git (push)
destination https://XXX@bitbucket.org/crowddoingmedicinalfoods/react.git (fetch)
destination https://XXX@bitbucket.org/crowddoingmedicinalfoods/react.git (push)
origin  https://github.com/ItsAntP/axios-react-github.git (fetch)
origin  https://github.com/ItsAntP/axios-react-github.git (push)
upstream    https://github.com/ItsAntP/axios-react-github.git (fetch)
upstream    https://github.com/ItsAntP/axios-react-github.git (push)

$ git remote add origin https://XXX@bitbucket.org/crowddoingmedicinalfoods/react.git
fatal: remote origin already exists.

$ git push origin master
Everything up-to-date

$ git push -u origin master
Branch 'master' set up to track remote branch 'master' from 'origin'.
Everything up-to-date

1 个答案:

答案 0 :(得分:2)

当前方法的问题

$ git init
$ git remote add origin https://XXX@bitbucket.org/crowddoingmedicinalfoods/react.git
$ git push -u origin master
remote: Forbidden
fatal: unable to access 'https://XXX@bitbucket.org/crowddoingmedicinalfoods/react.git/': The requested URL returned error: 403

这表明您尝试推送到Bitbucket时收到403禁止错误(很可能是因为您没有通过身份验证)。我不熟悉Bitbucket,但是当推送到GitHub存储库时,在配置远程存储库URL时,我使用SSH传输而不是HTTPS。 Atlassian网站提供了有关如何use SSH with Bitbucket的良好文档,因此,我建议您在继续操作之前让此部分正常工作。

$ git clone https://github.com/ItsAntP/axios-react-github.git
$ git remote -v
another_origin  https://github.com/ItsAntP/axios-react-github.git (fetch)
another_origin  https://github.com/ItsAntP/axios-react-github.git (push)
destination https://XXX@bitbucket.org/crowddoingmedicinalfoods/react.git (fetch)
destination https://XXX@bitbucket.org/crowddoingmedicinalfoods/react.git (push)
origin  https://github.com/ItsAntP/axios-react-github.git (fetch)
origin  https://github.com/ItsAntP/axios-react-github.git (push)
upstream    https://github.com/ItsAntP/axios-react-github.git (fetch)
upstream    https://github.com/ItsAntP/axios-react-github.git (push)
$ git remote add origin https://XXX@bitbucket.org/crowddoingmedicinalfoods/react.git
fatal: remote origin already exists.

在这里,从上一个origin命令可以看出,https://XXX@bitbucket.org/crowddoingmedicinalfoods/react.git已经设置为git remote -v


建议的方法

以下是我将要从一个远程存储库更改为另一个存储库的步骤:

# Change to parent directory (something other than desktop preferably)
cd /Users/appleuser/Desktop/

# Delete current directory.
rm -rf axios-react/

# Clone the GitHub repository into the `axios-react` directory.
# Use the `-o` option to identify the remote repository as `github` rather than `origin`.
git clone -o github https://github.com/ItsAntP/axios-react-github.git axios-react

# Change into the repository directory
cd axios-react

# Now add the URL of the Bitbucket remote repository as `origin`.
git remote add origin https://XXX@bitbucket.org/crowddoingmedicinalfoods/react.git

# Ensure that are authenticated with Bitbucket before attempting to push to it.
git push -u origin master