user230137 user230137 - 4 months ago 7x
Linux Question

Mercurial like method for creating git remote repository

When I was using Mercurial, creating a remote repository is one command line:

hg clone local remote

Where remote is something accessible via ssh.

I don't know if it is a functionality in Mercurial or we have installed something to make that possible.

Is there any way to do that with git? Or install something that will allow me to do the same like with Mercurial?


My question is not 'How to clone a remote repository?'


No, you can't do that with a single command, and you can't do that using Git alone either.

You roll something like this:

  1. Initialize a repository on the server:

    ssh user@server git init --bare /path/to/the/new/repo
  2. Push your local repository there:

    git push --all --tags ssh://user@server/path/to/the/new/repo

If you intend to work with that new remote repository (push/fetch) afterwards, it makes sense to add it as a named remote, so your step #2 becomes:

git remote add foo ssh://user@server/path/to/the/new/repo
git push --all --tags foo