In Git, how can I add a remote origin server when my host uses a different SSH port?
git remote add origin ssh://user@host/srv/git/example
Best answer doesn't work for me. I needed ssh://
from the beggining.
# does not work
git remote set-url origin [email protected]:10000/aaa/bbbb/ccc.git
# work
git remote set-url origin ssh://[email protected]:10000/aaa/bbbb/ccc.git
Rather than using the ssh://
protocol prefix, you can continue using the conventional URL form for accessing git over SSH, with one small change. As a reminder, the conventional URL is:
git@host:path/to/repo.git
To specify an alternative port, put brackets around the user@host
part, including the port:
[git@host:port]:path/to/repo.git
But if the port change is merely temporary, you can tell git to use a different SSH command instead of changing your repository’s remote URL:
export GIT_SSH_COMMAND='ssh -p port'
git clone git@host:path/to/repo.git # for instance
For those of you editing the ./.git/config
[remote "external"]
url = ssh://[email protected]:11720/aaa/bbb/ccc
fetch = +refs/heads/*:refs/remotes/external/*
for gitlab, example ssh port is 2224, therefore:
git remote add ssh://[email protected]:2224/your_group/your_project.git