git remote add with other SSH port

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

  • List files with git ls-files from root instead of current working directory
  • Is it possible to use pip to install a package from a private github repository?
  • Git- how to checkout a specific version (commit hash) in Teamcity?
  • Merge two git repositories of same project
  • how to remove untracked files in Git?
  • How to git push to remote if remote does not exist at all
  • git project vs repository, what's the fundamental difference?
  • Is there a way to purge some files from the history of git?
  • Highlighting added/deleted lines, ignoring moves, in a patch file
  • How to use a Git repository as an exploded war?
  • “Git Clean -fdx” recovery… possible?
  • Ignoring symlinks in git
  • 5 Solutions collect form web for “git remote add with other SSH port”

    You can just do this:

    git remote add origin ssh://user@host:1234/srv/git/example

    1234 is the ssh port being used

    You need to edit your ~/.ssh/config file. Add something like the following:

        Port 1234

    A quick google search shows a few different resources that explain it in more detail than me.

    For those of you editing the ./.git/config

    [remote "external"]                                                                                                                                                                                                                                                            
      url = ssh://                                                                                                                                                                                                               
      fetch = +refs/heads/*:refs/remotes/external/* 

    Best answer doesn’t work for me. I needed ssh:// from the beggining.

    # does not work
    git remote set-url origin
    # work
    git remote set-url origin ssh://

    Found this link, and although it was helpful my blog entry might help clarify it:

    Basically i think its much better to just edit your .git/config file and make the changes. Hopefully this will help someone else..

    Git Baby is a git and github fan, let's start git clone.