This is a surprisingly common ask I’ve gotten over the years, if you are moving code around either from public forks into private repos. Or if you are migrating your code from one github to another. Below are the steps:
Step 1 – Perform a clone of the source repo.
Step 2 – Add a git remote for the upstream repo:
git remote add new-origin {url of new repo}
Step 3 – Make sure any files are added and committed.
git add .
git commit -a -m "{Message for the commit}"
Step 4 – Push the changes to your repo:
git push new-origin main
Step 5 – Remove your original “origin” to “source-repo”:
git remote rename origin source-repo
Step 6 – Rename your other remote to “origin”:
git remote rename new-origin origin
Step 7 – Confirm setting with these commands:
git remote get-url origin
git remote get-url source-repo
Step 8 – Then you want to set the upstream:
```
git branch --set-upstream-to=origin/main
```