Loading...

Push code to two or more remotes in Git or have two push urls for a single remote

question devtips git
Ram Patra Published on July 14, 2025

You can add multiple remotes to a Git repository. This is useful if, for example, you want to push code to both GitHub and GitLab, or collaborate with multiple forks.

Add a second remote:

git remote add <remote-name> <remote-url>

Example:

Suppose your main remote is origin (default), and you want to add a second one called backup:

git remote add backup https://gitlab.com/yourusername/yourrepo.git

Check remotes:

git remote -v

Push to specific remote:

git push origin main     # push to GitHub
git push backup main     # push to GitLab

Fetch from all remotes:

git fetch --all

You can add as many remotes as needed — just give each one a unique name.


You can have multiple URLs for the same remote name (like origin) in Git — but with some limitations and use cases:

Use Case 1: Push to multiple URLs at once

You can set multiple push URLs for a single remote. This is helpful when you want to push to several repositories simultaneously (e.g., GitHub and GitLab).

Example:

git remote set-url --add --push origin https://github.com/youruser/yourrepo.git
git remote set-url --add --push origin https://gitlab.com/youruser/yourrepo.git

Now when you do:

git push origin main

It will push to both URLs.

But: For fetching, Git supports only one fetch URL per remote.

If you try:

git remote set-url --add origin https://github.com/youruser/yourrepo.git
git remote set-url --add origin https://gitlab.com/youruser/yourrepo.git

…then Git will use only the last one for fetches.

To check what’s set:

git remote show origin

  • Use multiple push URLs for origin
  • Use separate remotes (origin, gitlab, etc.) if you also want to fetch from multiple places

Note: If you’re using Git LFS in this setup where there are multiple push urls for a single remote, you will have to explicitly add the large files to each of the push urls like git lfs push --all https://gitlab.com/youruser/repo.git.

Take your presentation to the next level.

Put your face and name on your screen.

Your to-dos on your menu bar.

Fill forms using your right-click menu.

Ram Patra Published on July 14, 2025
Image placeholder

Keep reading

If this article was helpful, others might be too

question devtips app-store September 29, 2024 How to add a bullet point in app descriptions for the Mac App Store?

To add a bullet point (•) in app descriptions for the Mac App Store, follow these steps:

question devtips git September 22, 2024 How to upload large files to a git repository?

By default, you cannot upload files larger than ~100MB (for most Git hosting service providers). If you do so, the git push command will fail with an error. The recommended way to work with large files is to use Git LFS.

question devtips chromium August 27, 2020 How to take screenshots of the entire webpage without any extensions?

I always used an extension like Awesome Screenshot in Chrome to take screenshots of any website. However, you do not need an extension to capture a screenshot of a webpage.

Like my work?

Please, feel free to reach out. I would be more than happy to chat.