I have used git for over 2 years and never had a reason to push to two different remote repositories from one single codebase. Just yesterday, I stumbled upon a reason and had to do some research.
I found a way and thought to share, just in case it may come handy. Note that this can work for multiple repositories even if they are hosted with same or different git companies.
To see the effect of the commands that we will be experimenting, open the file
.git/config and observe.
Lets suppose you have repositories with the addresses;
[email protected]:nuhu-ibrahim/project.git [email protected]:nuhu-ibrahim/project.git
To set up the push URLs, execute the following:
git remote set-url --add --push origin [email protected]:nuhu-ibrahim/project.git git remote set-url --add --push origin [email protected]:nuhu-ibrahim/project.git
Executing these commands will add the new repositories to the remote.origin.pushurl config entry. Henceforth, pushes will send to both of these destinations, rather than the fetch URL.
To check out the status and content of the .git/config, run:
git remote show origin
To push, you can then run: