🚀 How I Accidentally Summoned Git Demons (and Eventually Learned How to Clone My Repo the Right Way)

Created by eneaslari 14/11/2025

webdev coding

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 init created 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:

  1. Remove secrets from code

  2. Replace them with environment variables:

    const GOOGLE_CLIENT_ID = process.env.GOOGLE_CLIENT_ID;
    
  3. Create a .env file

  4. Add .env to .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. 😄

More to read


🚀 How I Accidentally Summoned Git Demons (and Eventually Learned How to Clone My Repo the Right Way)
14/11/2025

A fun, step-by-step story of how I cloned my existing website repo to create a modified version without touching the original—while accidentally adding the wrong origin, dealing with “main vs master,” triggering GitHub’s secret-scanning police, and ultimately learning how to properly duplicate a repo, clean commits, remove secrets, and push safely. A lighthearted guide for anyone who wants to use an existing project as a template without the Git chaos.

🐳 The Complete Guide to Dockerizing a Node.js + Express App with Database & File Uploads
13/8/2025

This guide explains how to build, run, and persist a Node.js + Express application inside Docker — with support for MongoDB, PostgreSQL, and file uploads — and also clarifies the relationship between images, containers, and volumes.

My New Plan: Making a Mini-Game Every Week
21/2/2025

This week, I realized that working on big projects can sometimes feel slow, and it’s easy to lose motivation. So, I came up with a new plan—I’ll create and release a small game every week!

Making Tic-Tac-Toe and Sudoku in Just a Few Hours
20/2/2025

This week, I decided to take a break from my main game project and create something simple: **a Tic-Tac-Toe and a Sudoku game**.