How to sync my commits with multiple repositories in git?

There are many ways of doing this, some include custom scripts, app and even some paid services. We will do this using the simplest way of having multiple urls for a single remote.

Let’s say you have added your original remote like this:

$ git remote add origin origin-host:path/to/project.git

What many people don’t know is that you have an option to added multiple hosts for the same remote. You can do this by simply adding your second host to same remote like this:

$ git remote set-url --add origin second-host:path/to/project.git

You can do this any number of times you want can have any number of hosts..

$ git remote set-url --add origin third-host:path/to/project.git
$ git remote set-url --add origin fourth-host:path/to/project.git
$ git remote set-url --add origin fiveth-host:path/to/project.git

Your config file will look something like this:

[remote "origin"]
    url = origin-host:path/to/project.git
    url = second-host:path/to/project.git
    url = third-host:path/to/project.git

Now you can simply push your changes with a single command and they will be synced to all repositories.

$ git push origin {branch name}

Leave a Reply