Changing Git remote URL updates fetch but not push
I am attempting to change the remote URL of my origin branch in Git. All I want to change is the SSH port. First, listing my remote origins gives me this:
git remote -v origin email@example.com:package/name.git (fetch) origin firstname.lastname@example.org:package/name.git (push)
Then, I run the
set-url command to change my origin URL:
- Using git with ssh for Phabricator
- EC2 can't SSH into github
- Git repo access issue
- Command to create ssh config file using git bash(windows)?
- Using git with ssh-agent on Windows
- Jenkins, SSH plugin, 0 files transferred
git remote set-url origin ssh://email@example.com:XX/package/name.git (XX is my port #)
Now, I can fetch without issue, but pushing my branch to origin doesn’t work, because the push URL didn’t change. Listing my remotes again I get this:
git remote -v origin ssh://firstname.lastname@example.org:XX/package/name.git (fetch) origin email@example.com:package/name.git (push)
Why did my
set-url command only change the fetch URL?
One Solution collect form web for “Changing Git remote URL updates fetch but not push”
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://firstname.lastname@example.org:XX/package/name.git