Techtrekking

How to reuse existing Gthub Repo without deleting your existing code

By Pravin•

Step-by-step

1. Go to your old repository on GitHub

Make sure the current main branch still has the old code.

2. Create a branch + tag for the old version

Run these commands locally (while you still have the old code):

# Clone the old repo (if you don't have it locally anymore) git clone https://github.com/YOUR_USERNAME/YOUR_PROJECTNAME.git cd YOUR_PROJECTNAME # Create a branch for the old version git branch archive/v1-old git push origin archive/v1-old # Create a tag (recommended) git tag v1.0-final git push origin v1.0-final

3. Replace main with your new architecture

Now go to your new local folder (the rearchitected code):

cd path/to/your/new/rearchitected-folder # Initialize git if you haven't already git init git add . git commit -m "feat: complete rearchitecture of the website" # Link to the existing GitHub repo git remote add origin https://github.com/YOUR_USERNAME/YOUR_PROJECTNAME.git # Force push the new code to main git branch -M main git push -u origin main --force

Final Result

WhatLocation
New architecturemain branch
Old codebasearchive/v1-old branch
Old version (tagged)Tag v1.0-final
Repo nameStill YOUR_PROJECTNAME (unchanged)

Bonus: Make it clearer

After pushing, edit the README.md in the new main and add this at the top:

> **Note**: This is a complete rearchitecture. > Old version is available in the branch [`archive/v1-old`](https://github.com/YOUR_USERNAME/YOUR_PROJECTNAME/tree/archive/v1-old) > and tagged as `v1.0-final`.

This is the simplest clean way — no need to rename the repo or create a new one.

Would you like me to give you the exact commands in one copy-paste block?

Comments
No comments yet. Be the first to comment!
Leave a Comment
Your comment will be visible after approval.