Skip to main content

Command Palette

Search for a command to run...

How to Move a Complete Git Repository

Updated
1 min read

Moving a Git repository while preserving all branches, tags, and history requires careful handling. This guide covers the step-by-step process to migrate your repository safely.

Quick Method

For those familiar with Git, here's the quick version:

git clone --mirror $ORIG_REPO_URL temp-dir
cd temp-dir
git remote rm origin
git remote add origin $NEW_REPO_URL
git push origin --all
git push --tags

Detailed Steps

  1. Clone the Original Repository

     git clone --mirror $ORIG_REPO_URL temp-dir
    

    The --mirror flag creates a bare repository, including all branches and tags.

  2. Navigate to Directory

     cd temp-dir
    
  3. Update Remote Configuration

     git remote rm origin
     git remote add origin $NEW_REPO_URL
    

    This step redirects the repository to its new destination.

  4. Push All Content

     git push origin --all
     git push --tags
    

    These commands transfer all branches and tags to the new location.

Verification

After migration, verify:

  • All branches are present in the new repository

  • Commit history is intact

  • Tags are properly transferred

  • Remote URLs are correctly configured

More from this blog

DevKata Dojo

8 posts

Dedicated to sharing insights, tips, and experiences from my journey through the world of software development. I'm a passionate developer constantly exploring new technologies and techniques.