Though it’s not very common in my daily work, I occasionally need to add additional remote Git repositories mainly for pushing. In fact, I did this about 4 to 5 times already, and thought that it’d be the last time.

Today, I need do this again, and I forgot!

Currently, I have the following remote repository set for ‘origin’:

❯ git remote -v
origin  git@git.homeserver.local:kenno/ansible.git (fetch)
origin  git@git.homeserver.local:kenno/ansible.git (push)

I wanted to add https://kenno@gitea.homeserver.local/kenno/ansible.git as the additional repo for pushing.

In order to achieve this, I need to re-add the existing repo followed by the 2nd repo. I’m not sure if there is a better way to do this. But this is how I got it working.

❯ git remote set-url origin --push --add git@git.homeserver.local:kenno/ansible.git
❯ git remote set-url origin --push --add http://kenno@gitea.homeserver.local/kenno/ansible.git

Now, let’s verify it.

❯ git remote -v
origin  git@git.homeserver.local:kenno/ansible.git (fetch)
origin  http://kenno@gitea.homeserver.local/kenno/ansible.git (push)
origin  git@git.homeserver.local:kenno/ansible.git (push)

That’s it. If I come across a fancy way which requires to add just the additional repo without re-adding existing ones, I will update this post. As for now, I’m happy with this method.

Reference: