You’re describing a setup where you want to:
This is commonly done by forking a repository manually and then setting the original repository as a remote called upstream.
Here’s how you can do it step by step:
git clone https://github.com/original-user/original-repo.git
cd original-repo
origin remote (optional)If you want to keep using the original repo as origin, skip this step.
If you’re going to push to a new repository (your own), it’s better to rename origin to upstream:
git remote rename origin upstream
You can now pull from the original using:
git pull upstream main
Replace
mainwith whatever the default branch is (oftenmasterormain).
Create a new empty repo on your Git provider (e.g., https://github.com/your-user/my-new-repo.git).
origingit remote add origin https://github.com/your-user/my-new-repo.git
To verify:
git remote -v
You should see:
origin https://github.com/your-user/my-new-repo.git (fetch)
origin https://github.com/your-user/my-new-repo.git (push)
upstream https://github.com/original-user/original-repo.git (fetch)
upstream https://github.com/original-user/original-repo.git (push)
Make sure all branches are pushed to your new origin:
git push -u origin main
Whenever you want to sync updates from the original repository:
git fetch upstream
git merge upstream/main
Or, if you’re using rebase:
git fetch upstream
git rebase upstream/main
| Task | Command |
|---|---|
| Clone original | git clone ... |
Rename origin to upstream |
git remote rename origin upstream |
| Add your own repo | git remote add origin ... |
| Pull from original | git pull upstream main |
| Push to new repo | git push -u origin main |
Let me know if you want a script to automate this.