Skip to main content
Kubernetes Made Easy! Instantly spin up best-practice clusters with GetInfra templates. Browse Now

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 & Software Developer | Automating & Scaling Infrastructure

💡 Working with Kubernetes, Istio, and DevOps. Got questions? Feel free to reach out!


No comments are allowed for this post