A.P.
A.P.

Reputation: 1

Forking an existing GitHub repo to Bitbucket

I am having difficulty trying to fork my existing GitHub repo to Bitbucket. I used the terminal to use the git remote add like it stated on the directions but it kept on reporting fatal: the remote origin already exists. Also when I try to push it, nothing happens. I've looked at the answers on here to change the name, but I have been with using the GitHub link, and nothing happens. I don't know if I properly called my fork remote origin and the original repo upstream. Has anyone else had a similar problem that I'm experiencing? I'm fairly new to how this works and still learning along the way.

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://[email protected]/crowddoingmedicinalfoods/react.git

$ git push -u origin master
remote: Forbidden
fatal: unable to access 'https://[email protected]/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://[email protected]/crowddoingmedicinalfoods/react.git (fetch)
destination https://[email protected]/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://[email protected]/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

Upvotes: 0

Views: 1927

Answers (1)

Anthony Geoghegan
Anthony Geoghegan

Reputation: 11983

Issues with current approach

$ git init
$ git remote add origin https://[email protected]/crowddoingmedicinalfoods/react.git
$ git push -u origin master
remote: Forbidden
fatal: unable to access 'https://[email protected]/crowddoingmedicinalfoods/react.git/': The requested URL returned error: 403

This shows that you got a 403 Forbidden error when you tried to push to Bitbucket (most likely because you are not authenticated to do so). I’m not familiar with Bitbucket but when pushing to GitHub repositories, I use the SSH transport rather than HTTPS when configuring remote repository URLs. The Atlassian website provides good documentation on how to use SSH with Bitbucket so I’d advise getting this part working before proceeding.

$ 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://[email protected]/crowddoingmedicinalfoods/react.git (fetch)
destination https://[email protected]/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://[email protected]/crowddoingmedicinalfoods/react.git
fatal: remote origin already exists.

Here, origin was already set to https://[email protected]/crowddoingmedicinalfoods/react.git as can be seen from the previous git remote -v command.


Suggested approach

Here are the steps, I would take to change from one remote repository to another:

# 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://[email protected]/crowddoingmedicinalfoods/react.git

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

Upvotes: 2

Related Questions