Kubernetes Made Easy! Instantly spin up best-practice clusters with GetInfra templates. Browse Now
Alex's Coding Blog
  • home
  • about
  • projects
  • contact

Blog

Copy Git repository with branches to another server

  • March 14, 2021 March 16, 2025
  • by Alexander

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
How-to
Alexander Lvovich

Solution Architect & Software Developer | Automating & Scaling Infrastructure

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

Share on:

No comments are allowed for this post

Recent Posts

  • Securing Web Services Against Unwanted Traffic with NGINX
  • Optimizing API by Offloading Responsibilities to an API Gateway
  • How to Clean Up Local Branches of Remote Merged Branches
  • Resolving Namespace Overriding in Argo CD with Kustomize
  • Connecting to Gitlab's private Nuget registry
  • Why Istio?

Categories

  • Azure
  • Architecture
  • .NET Core
  • Certification
  • DevOps
  • How-to
  • Azure Functions
  • Serverless
  • Cosmos DB
  • Security
  • Thoughts
  • Kubernetes
  • Istio
© Copyright 2025, Alexander Lvovich. Theme by Colorlib
I use cookies and similar technologies on our website to enhance your browsing experience and analyze website traffic. By clicking "Accept," you consent with my Privacy Policy to the use of these technologies.
Accept