3days since the last Git and AI fuck-up

How to sync my commits with multiple repositories in git?

Mandeep Singhfrom the archive

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

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

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

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

You can do this whenever you want to have any hosts.

shell
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:

shell
[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 push your changes with a single command, which will be synced to all repositories.

shell
git push origin {branch name}

Further Reading:

How to push to multiple git remotes at once. Useful if you keep mirrors of your repo.
How to push to multiple git remotes at once. Useful if you keep mirrors of your repo. - git-pushing-multiple.rst

Originally Posted On: StackOverflow

Tagged solving-mistories, git-remote, git-push