将GitHub现有仓库复刻至Bitbucket时遇Git操作问题求助
Hey there, let's break down what's going on here and fix it step by step—since you're new to Git, I'll keep things clear and straightforward!
First, let's untangle your messy remote repositories
Looking at your git remote -v output, you've got duplicate remotes pointing to the same GitHub repo, plus a Bitbucket remote named destination—this is why you're getting errors like "remote origin already exists." Let's clean this up first:
# Remove all extra, duplicate remotes git remote remove another_origin git remote remove upstream git remote remove destination
Now run git remote -v again, and you should only see your original GitHub repo listed as origin.
Fix the 403 Forbidden error (Bitbucket permission issue)
That error happens because Bitbucket no longer allows using your regular account password for HTTPS pushes. You need to use an App Password instead:
- Log into Bitbucket, go to your Personal Settings
- Find the App passwords section, create a new password
- Check the "Repository write" permission (and any others you need)
- Save this password—you'll only see it once!
Set up your remotes correctly (aligning with Git best practices)
Since you want to "fork" your GitHub repo to Bitbucket, here's the standard way to structure your remotes:
origin: Your own Bitbucket repo (the one you're pushing to)upstream: The original GitHub repo (so you can pull updates later if needed)
First, rename your current GitHub remote from origin to upstream:
git remote rename origin upstream
Then add your Bitbucket repo as the new origin:
# Replace YOUR_APP_PASSWORD with the one you just created git remote add origin https://YOUR_BITBUCKET_USERNAME:YOUR_APP_PASSWORD@bitbucket.org/crowddoingmedicinalfoods/react.git
Push your code to Bitbucket
Now you can push your master branch to Bitbucket with:
git push -u origin master
The -u flag sets up tracking, so next time you just need to run git push origin to sync changes.
Quick note on naming conventions
originis always the repo you own and push changes to (your Bitbucket fork here)upstreamis the original repo you forked from (your GitHub repo in this case)
This setup keeps things organized and avoids confusion down the line.
内容的提问来源于stack exchange,提问作者A.P.

