Hanxue
Hanxue

Reputation: 12766

Setting git remote fetch and push url in a single command

The command

$ git remote set-url origin [email protected]:myorg/myrepo.git

will only set the fetch URL, not the push URL:

$ git push origin
remote: Too many invalid password attempts. Try logging in through the website with your password.
fatal: unable to access 'https://bitbucket.org/myorg/myrepo.git/': The requested URL returned error: 403
$ git remote -v
origin  [email protected]:myorg/myrepo.git (fetch)
origin  https://bitbucket.org/myorg/myrepo.git (push)

I have to set the push URL separately

$ git remote set-url --push origin [email protected]:myorg/myrepo.git

Question

I recall having been able to set both push and fetch URL in a single command.

  1. Was there a change in git so that git remote set-url will only change the fetch URL by default?
  2. Is there a way to set both URL in a single command?

Upvotes: 1

Views: 3535

Answers (2)

phd
phd

Reputation: 94511

After you've used git remote set-url --push there are 2 URLs for a remote (for fetching and pushing) and git remote set-url only changes the fetch URL. To make git remote set-url change both URLs just remove pushurl from that remote.

Upvotes: 3

oklas
oklas

Reputation: 8220

By default it always add or set both url (fetch and push).

Was there a change in git so that git remote set-url will only change the fetch URL by default?

When you at least once to do change remote with key --path it will update it separately: fetch with no key --path, and path with key --path

Is there a way to set both URL in a single command?

  • Remove your url by name.
  • Add it again with no --push key It will now set both url (push and fetch) for that remote.

Upvotes: 1

Related Questions