Skip to main content
Struggling to hire strong frontend developers? Analyze real GitHub code with AI — not take-home tests. Learn More

Copy Git repository with branches to another server

I'm migrating a legacy projects from one git server to another. I would like to keep all branches with me and not only the main.

In general, the steps can be summirized as follows:

  • Clone remote repo locally
  • checkout all remote branches
  • Change origin url to new server
  • Push everything to new origin

Clone repository to local git repo

git clone

Run script to checkout allthe branches

#!/bin/bash

for remote in `git branch -r`; do git branch --track ${remote#origin/} $remote; done

Fetch all

git fetch --all
git pull --all
git fetch --tags

Check if required branches pulled locally

git branch

Replace origin url

git remote rm origin
git remote add origin https://new.server/project/app.git

Push all branches to new origin

git push origin --all
git push --tags

Share this article

About the Author

Alexander Lvovich

Alexander Lvovich

Solution Architect | Cloud-Native Platforms, DevOps & Service Mesh

💡 Kubernetes architecture, Istio service mesh, CI/CD, and cloud-native DevOps — from strategy to hands-on implementation. Reach out if you need expert support.


No comments are allowed for this post