Sometimes I need to connect my local code with two remote copies of the same repository to upload the changes on both of them and to maintain both copies updated. It happens when I want to have a copy internal to the company of the code of an external repository to which we had been given temporary access, or during the migration of projects from one GIT server to another, when both servers needed to be updated.
Prerequisites:
- We need to start from a situation in which the two repositories (the one on gitserverA and the one on gitserverB) are aligned, for example after having locally cloned the repository downloaded from gitserverA and just uploaded it to the gitserverB.
- The development branch is called dev.
At this point, to link the two repositories, we need to associate to a remote repository (called “all“, for example) all the repository you want to link:
git remote add all https://gitserverA/myproject/myproject-backend.git
git remote set-url --add --push all https://gitlab.aks.sns.it/myproject/myproject-backend.git
git remote set-url --add --push all https://gitserverA/myproject/myproject-backends.git
git checkout dev
# ... updates to the code and commits ...
git push all dev
After these configurations you can work locally, modify the code as you want and then push the changes to both repositories.
Other commands useful in these situations:
# check the current branch
git branch
# list all the branches
git branch -a
# list all remotes
git remote -v
Sources and references:
- [1] Git Basics – Working with Remotes, Git-Scm.
- [2] Managing remote repositories, GitHub.
- [3] Using git with multiple remote repositories, Michael S. Mikowski.
- [4] How can I pull/push from multiple remote locations?, StackOverflow.
- [5] Working with Git remotes and pushing to multiple Git repositories, Jigarius.
- [6] Git push to multiple remotes, Patrick Connelly.
- [7] GIT: Schema di funzionamento, Claudio Battaglino.
Fascinating blog! Is your theme custom made or did you download it from somewhere?
A design like yours with a few simple adjustements would really make myy blog stand out.
Please let me know where you got your theme.
Hi,
I bought this theme: VT Grid Mag