In the middle of the desert you can say anything you want

15 Feb 2022

Git adding another remote

Not the first time I’m touching the topic here :) But yet another repo to set up, and realized I didn’t really get “new remote” vs “remote URI”

Details: Managing remote repositories - GitHub Docs

Adding another remote

Easy simple take: How to Add a New Remote to your Git Repo | Assembla Help Center

# add
git remote add remote_name_github

# show the result ('verify')
git remote -v

# push _specifically to that remote_
git push remote_name_github

Adding another remote URI, to push to both at the same time

Github 1 helps:

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

… and gives the neat idea to create a remote named all for this purpose, as opposed to changing ‘origin’! That answer is really detailed and shows the process

Adding a remote with multiple pushurls

# take an existing repo, located at remote_uri

# add a remote with that URI
> git remote add all remote_uri

# overwrite its push URI with another one
> git remote set-url --add --push all all_push_uri_overrides_main_uri
# add the original one back
> git remote set-url --add --push all remote_uri

# Two remotes now
> git remote show

> git remote show all
* remote all
  Fetch URL: remote_uri
  Push  URL: remote_uri
  Push  URL: all_push_uri_overrides_main_uri
  HEAD branch: master
  Remote branch:
    master new (next fetch will store in remotes/all)
  Local ref configured for 'git push':
    master pushes to master (up to date)

I think I got it now. My error was from not understanding that adding a push URI with --add overwrites the existing push URI, and I had to add it again to get the previous one working too.

  1. github - Git - Pushing code to two remotes - Stack Overflow ↩︎

Nel mezzo del deserto posso dire tutto quello che voglio.