Detach your current repo from one remote and attach it to your fork
You basically want to detach your current repo from one remote and attach it to your fork. This is straightforward in Git—you're just updating the origin.
✅ Step 1: Check current remote
git remote -v
You’ll see something like:
origin https://github.com/company/repo.git (fetch)
origin https://github.com/company/repo.git (push)
๐ Step 2: Unlink (remove existing remote)
git remote remove origin
Now your repo is no longer connected to anything.
๐ Step 3: Link to your forked repo
First, copy your fork URL from GitHub (something like):
https://github.com/your-username/repo.git
Then run:
git remote add origin https://github.com/your-username/repo.git
๐ Step 4: Verify
git remote -v
Now it should point to your fork.
⬆️ Step 5: Push your code to fork
If your local branch is main:
git push -u origin main
๐ก Pro Tip (Best Practice for Forks)
If you still want to pull updates from the original repo:
git remote add upstream https://github.com/original-owner/repo.git
Now you have:
origin→ your fork (push here)upstream→ original repo (pull updates)
⚠️ Common Pitfall
If you get:
fatal: remote origin already exists
That means you didn’t remove it properly—run:
git remote remove origin
again.
If you want, I can show you a clean workflow for fork → upstream sync → PRs (very useful in company setups).
Comments
Post a Comment