So there I was… All I wanted was something simple: duplicate my existing website repo, give it a new name, and use it as a template to build a modified version of my site.
Easy, right?
HAHAHA. Welcome to GitHub, my friend. 😅
This is the story of how:
- I cloned my repo
- Created a new repo
- Added the wrong origin
- Pushed the wrong branch
- Got blocked by GitHub’s secret-scanning police
- And learned how Git really works
And now I’m writing this so future-me doesn’t cry again.
Grab popcorn. 🍿
🧩 Step 1 — Cloning the Existing Repo (The Innocent Beginning)
My goal: 👉 Make a modified version of my current site without touching the original repo.
So the first move was to simply clone the repo:
git clone https://github.com/USER/OLD-REPO.git
But here’s the twist: I didn’t want to mess with this repo at all.
So the correct move is:
Duplicate the folder
Windows: copy → paste
Mac: Option + drag
Linux:
cp -r old-repo new-repo
Now I have:
old-repo ← untouched
new-repo ← my new playground
Perfect. What could go wrong?
(Everything...)
🔥 Step 2 — Making the New Repo “Clean” (No History Allowed)
Since I wanted a fresh repo, not a fork or a mirror, I needed to remove the old .git folder:
rm -rf .git
This turns “new-repo” into a normal folder, not a git project.
Then:
git init
git add .
git commit -m "Initial commit"
🎉 Boom — fresh repo with the same code.
📦 Step 3 — Creating a New Repo on GitHub
On GitHub:
- Click New Repository
- Give it a new name
- Leave it empty (no README / no .gitignore)
- Copy the HTTPS URL
Then:
git remote add origin https://github.com/USER/NEW-REPO.git
All going well so far…
Until.
💥 Step 4 — The Origin Disaster
Guess what I did?
Yep.
I added the wrong origin. So now my repo was basically trying to push into a random universe.
But the fix was easy:
Option A — Replace the URL:
git remote set-url origin https://github.com/USER/CORRECT-REPO.git
Option B — Remove & re-add:
git remote remove origin
git remote add origin https://github.com/USER/CORRECT-REPO.git
Crisis avoided. For now. 😈
🧟 Step 5 — The “main vs master” Mystery
I tried to push:
git push -u origin main
Git said:
“main? never heard of her.”
Because my local git defaulted to master, not main. Why?
- GitHub switched to main in 2020
- My local Git didn’t get the memo
- So
git initcreated master
Solution:
Check branch:
git branch
If it's master, rename it:
git branch -M main
git push -u origin main
Or just push to master if you prefer:
git push -u origin master
Mystery solved. 🔍
🔒 Step 6 — GitHub Blocks My Push (Oops… My Secrets!)
GitHub suddenly turned into a security guard:
🚨 “Stop right there! We detected Google OAuth client IDs, client secrets, refresh tokens, and an Atlassian API token in your code. You’re not going ANYWHERE.”
Yep. My code had:
- Google OAuth client ID
- Google OAuth client secret
- Google refresh token
- Atlassian API token
ALL hard-coded in JavaScript. GitHub basically said:
“Buddy, this is why we can't have nice things.” 😑
Fix:
Remove secrets from code
Replace them with environment variables:
const GOOGLE_CLIENT_ID = process.env.GOOGLE_CLIENT_ID;Create a
.envfileAdd
.envto.gitignore
Optional but smart:
🩹 Rotate (regenerate) ALL the compromised secrets.
🔧 Step 7 — Rewrite the Bad Commit
Because secrets were already committed, the fix was:
git reset --mixed HEAD~1
git add .
git commit -m "Initial commit (clean)"
git push -u origin main
Finally — a push that GitHub allowed. Victory. 🏆
📈 Step 8 — Updating Git (Bonus Learning!)
I also learned how to upgrade Git itself because I got tired of master popping up.
Windows:
Download the installer from https://git-scm.com/download/win
macOS:
brew update
brew upgrade git
Ubuntu:
sudo add-apt-repository ppa:git-core/ppa
sudo apt update
sudo apt install git
Then I set the new default:
git config --global init.defaultBranch main
Now every new repo starts with main ❤️
🎉 Final Thoughts (a.k.a. What Future-Me Should Remember)
Cloning a repo as a template is easy if you follow the right steps:
✔ Keep the old repo untouched
✔ Duplicate the local folder
✔ Remove .git
✔ Re-initialize the repo
✔ Add a new origin
✔ Fix branch names if needed
✔ NEVER commit secrets
✔ Let GitHub save you from yourself
And now… Future me, if you’re reading this:
Don’t panic next time. You’ve got this. 😄