Changing Git remote URL updates fetch but not push
As long as the config file for the repo in question contains an entry for the push URL, set-url
will only update the fetch URL by default.
[remote "origin"]
url = fetch.git
fetch = ...
pushurl = push.git
As the answer of running.t explains, you can use set-url --push
to change this entry. However, you will have to keep doing this every time the URL changes.
To restore the default behavior of set-url
(which changes both URLs at once), just delete the entry from the config. Or delete it using set-url --delete
:
git remote set-url --delete --push origin push.git
As for why a repository would ever contain a separate push url without you adding it: Some git clients like Sourcetree "helpfully" do this.
From git-remote
manual:
set-url
Changes URL remote points to. Sets first URL remote points to matching regex <oldurl> (first URL if no <oldurl> is given) to <newurl>. If <oldurl> doesn’t match any URL,
error occurs and nothing is changed.
With --push, push URLs are manipulated instead of fetch URLs.
So you should additionally execute:
git remote set-url --push origin ssh://[email protected]:XX/package/name.git