DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Runtime FinOps: Making Cloud Cost Observable
  • Shrink a Bloated Git Repository and Optimize Pack Files
  • Open-Source GitOps at the Edge: Deploying to Thousands of Clusters With Rancher Fleet
  • From Command Lines to Intent Interfaces: Reframing Git Workflows Using Model Context Protocol

Trending

  • Java Backend Development in the Era of Kubernetes and Docker
  • How to Prevent Data Loss in C#
  • Building a Skill-Based Agentic Reviewer with Claude Code: A Practical Guide Using Skills.MD, MCP Servers, Tools, and Tasks
  • Self-Hosted Inference Doesn’t Have to Be a Nightmare: How to Use GPUStack
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Mirroring Git Changes From One Server to Another Server

Mirroring Git Changes From One Server to Another Server

This article will help you to achieve the Git mirroring between one server to another server. Read on!

By 
Sankara Narayanan user avatar
Sankara Narayanan
·
Sep. 23, 20 · Analysis
Likes (2)
Comment
Save
Tweet
Share
7.6K Views

Join the DZone community and get the full member experience.

Join For Free

Introduction

Hello all, nowadays most of the development teams using GIT version control, some of you may have a requirement of mirroring your team's git changes from one server to another Git server. This article will help you to achieve the Git mirroring between one server to another server.

Business Case

I got one assignment wherein there will be 2 Git Servers, development will happen in one Git server and the changes should be synchronized to another Git server at regular intervals. But in my case, the complexity is both the servers are in different restricted network. So I have done the small experiment and it worked. And I am sharing the steps to you all in this article.

The Experiment Performed Using Below 2 GIT Servers

Main GIT Server: Let's take our main git server is located in our office and can be accessed only in-office network.

Mirror GIT Server: The mirror server is located at the vendor/client-side, which can be accessible in a normal internet connection but not with our office network. Since the office proxy will block the outside URL's. 

Now let's see how we can mirror the GIT projects between these 2 servers.

Step 1: Connected my laptop to my office LAN connection.

Step 2: Created a local folder and navigate to that using Git bash console

Step 3: Cloned the main Git server repository using clone command 

git clone --mirror

http://mainserver:8080/tfs/project1/_git/Experiment 

Step 4: Cd to the cloned repository root path

Step 5: Check the available branches in the cloned repository using “git branch –a” command

Step 6: Disconnect from your office network and connect to wifi/dongle internet access

Step 7: Next updated the Push URL to the Mirror Git server

git remote set-url --push origin

https://mirrorserver:8080/tfs/project1/git/Experiment 

Step 8: Validate the fetch and push origin URL’s, in our case, it looks like below

origin http://mainserver:8080/tfs/project1/_git/Experiment (fetch)

origin https://mirrorserver:8080/tfs/project1/git/Experiment (push) 

Step 9: Now Git Push the locally cloned main Git server repository to Mirror git server repository

Result

All the branches with history, tags are synchronized from your main Git server to mirror Git Server. 

Step 10: So whenever changes happened in the main server just execute the fetch command as below in your local workspace by connecting to your office LAN connection

Git fetch –p origin

This will fetch all the changes in your main Git server repo to your local workspace

Step 11: Then switch to the secondary server network and use the push command to sync the changes to the mirror server as below

Git push –mirror

All the latest changes will be now synchronized with the mirror GIT server.

Note: If your primary server and mirror server can be accessible from the same network then there is no need for switching network connection as mentioned in above step 6 and step 11. In my case, I cannot access the mirror server from my office network, so I switched to a public wifi/dongle connection and perform the mirroring options.

Conclusion

Thus mirroring a GIT server can be easily achieved using the above method, if you want to mirror the GIT server changes with another GIT server in the same network then you can also put the fetch and push command in the shell file and automate this synchronization process.

Git

Opinions expressed by DZone contributors are their own.

Related

  • Runtime FinOps: Making Cloud Cost Observable
  • Shrink a Bloated Git Repository and Optimize Pack Files
  • Open-Source GitOps at the Edge: Deploying to Thousands of Clusters With Rancher Fleet
  • From Command Lines to Intent Interfaces: Reframing Git Workflows Using Model Context Protocol

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook