Sometimes you need to create a full copy of an existing Git repository under a different remote—maybe you're taking a coding test, starting a new project based on a template, or preserving a snapshot of a public repo. Here's a quick way to duplicate a Git repo using the bare clone technique.
A bare clone creates a copy of the entire Git repository without a working directory (i.e., no checked-out files). This is ideal when you want to treat the repository like a pure archive or use it to push to another remote without interference from local files.
Here's how to do it step by step:
# 1. Clone the original repository as a bare repository
git clone --bare https://github.com/pieterclaerhout/tech-assessment.git
# 2. Navigate into the cloned directory
cd tech-assessment.git
# 3. Remove the old origin remote
git remote remove origin
# 4. Add your own new GitHub remote
git remote add origin https://github.com/pieterclaerhout/tech-assessment-pieterclaerhout.git
# 5. Push all branches and set upstream
git push -u origin main
Make sure the target repository already exists on GitHub, or you'll need to create it first.
This method is often used in situations where you need to:
- Submit your own version of a coding assignment based on a starter repo
- Duplicate a project template without creating a GitHub fork
- Preserve the commit history while changing ownership or remote
By using a bare clone, you get a clean, metadata-only copy that you can push anywhere—perfect for archiving or duplicating repos in a professional workflow.
If this post was enjoyable or useful for you, please share it! If you have comments, questions, or feedback, you can email my personal email. To get new posts, subscribe use the RSS feed.