Git Push to Two URL Simultaneously

Git can push one local branch to more than one remote URL at the same time by adding multiple pushurl values to a remote. This is useful when you want the same repository mirrored to two servers, such as a primary Git server and a backup repository.

Add two push URLs to origin:

git remote set-url --add --push origin git://original/repo.git
git remote set-url --add --push origin git://another/repo.git

After this, a normal push will send updates to both configured push URLs:

git push origin main

Check the current fetch and push URLs with:

git remote -v

You should see one or more origin entries marked as push.

Remove one push URL from origin:

git remote set-url --delete --push origin git://another/repo.git

Remove origin completely:

git remote rm origin

Set origin to a single URL again:

git remote set-url origin git://another/repo.git

If the remote does not exist yet, add it first:

git remote add origin git://another/repo.git

Note that git:// is unauthenticated and is often disabled on modern hosting services. For normal write access, use an SSH or HTTPS URL supported by your Git host, for example:

git remote set-url --add --push origin git@github.com:user/repo.git

Leave a Reply