Skip to content

Instantly share code, notes, and snippets.

@bjmiller121
Last active March 4, 2024 05:47
Show Gist options
  • Save bjmiller121/f93cd974ff709d2b968f to your computer and use it in GitHub Desktop.
Save bjmiller121/f93cd974ff709d2b968f to your computer and use it in GitHub Desktop.
Add multiple push URLs to a single git remote

Sometimes you need to keep two upstreams in sync with eachother. For example, you might need to both push to your testing environment and your GitHub repo at the same time. In order to do this simultaneously in one git command, here's a little trick to add multiple push URLs to a single remote.

Once you have a remote set up for one of your upstreams, run these commands with:

git remote set-url --add --push [remote] [original repo URL]
git remote set-url --add --push [remote] [second repo URL]

Once set up, git remote -v should show two (push) URLs and one (fetch) URL. Something like this:

$ git remote -v
origin git@github.com:bjmiller121/original-repo.git (fetch)
origin git@github.com:bjmiller121/original-repo.git (push)
origin git@github.com:bjmiller121/second-repo.git (push)

Now, pushing to this remote will push to both upstreams simultaneiously. Fetch and pull from this remote will still pull from the original repo only.

Tip: If you always want to push to both upstreams simultaneously, you might want to use the origin remote. If you only sometimes want to push to both, you might use a remote name like both to indicate that it will push to multiple repos.

@jamie-cyc
Copy link

How can I remove a specific push URL without editing my git config file directly?

@umkasanki
Copy link

umkasanki commented Jul 21, 2019

How can I remove a specific push URL without editing my git config file directly?

[remote "origin"]
	url = git@git.hyperlane.co:team/company/project.git
	fetch = +refs/heads/*:refs/remotes/origin/*
	pushurl = git@git.hyperlane.co:team/company/project.git
	pushurl = git@github.com:company/project.git
[branch "master"]

@perlduck
Copy link

perlduck commented Sep 3, 2020

git remote set-url --delete <name> <url>
that is:
git remote set-url --delete origin git@github.com:company/project.git
to remove the second URL in the above example.

@kosist
Copy link

kosist commented Oct 14, 2020

@perlduck, also --push parameter should be specified while deleting url, if that url was set using --push parameter
git remote set-url --delete --push origin git@github.com:company/project.git

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment