61

On one machine (IP address 192.168.1.2), I create a Git repository by

$ cd /home/hap/working
$ git init
$ (add some files)
$ git add .
$ git commit -m 'Initial commit'

And I have another machine on the same Wi-Fi network. How can I get clone from the other machine?

CharlesB
  • 86,532
  • 28
  • 194
  • 218
hap497
  • 154,439
  • 43
  • 83
  • 99

4 Answers4

112

You need to use a git+ssh URL to perform the Git cloning:

git clone git+ssh://hap@192.168.1.2/~/working

To break it down:

  • git+ssh tells Git that you want to use ssh to connect to the Git repository.
  • hap is your username (I assume based on the home directory in your question).
  • 192.168.1.2 is the machine that you want to connect to
  • ~/working is the path to your Git repository on the remote machine (so ~ is your home directory)

Some other things to note:

  • You need to have a ssh server enabled on the machine with the Git repository
  • You'll need to know the password for the user hap
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Josiah
  • 3,232
  • 3
  • 25
  • 25
  • 10
    I don't think `git+ssh://` is needed. You should be able to simply use `hap@192.168.1.2:~/working`. Also cloning directly from a working directory sets the clone up to push into that working repo, which should be avoided. – bames53 Feb 12 '13 at 21:45
  • 3
    This can be useful, for instance if you are working on machine X which can't access remote repo but can access another local machine that has access to remote. In my case I am using this where i develop on a linux machine with no access to the vpn needed to go straight to the remote. – Matt Wolfe Jul 12 '13 at 18:38
  • Is it as easy to clone using a certificate? – David Karlsson Feb 07 '17 at 10:09
  • what if the path of Git repository is not on the home directory? i.e `E://folder/working` what would i change to `~/working`? – kiLLua May 11 '17 at 07:16
  • I made use of `git clone git+ssh://..' because my use case is similar to @Matt Wolfe. The feature works fine for me on Mac OS X. – Bob Cochran Aug 27 '17 at 22:10
4

I think people are looking for this answer. The following command in the terminal wil login into the other computer and clone an existing repo. In the current path location of the terminal (so cd to the preferred location first).

git clone username@12.345.67.891:/home/path/to/repo.git

In case you do not now the IP address. Use ping to determine the ip of your server. After the IP address don't forget to use the use a : and then write the absolute path.

Michiel
  • 161
  • 8
3

I assume that on both machines you have installed Git.

Now what you do depends on what services you have installed, that is, how you can connect from one machine to the other.

The simplest case is when you have sshd running on the machine you want to clone from, and you can ssh from the machine you want to clone to to the machine you want to clone from.

If you can do

ssh 192.168.1.2

(or if you have different username on the other machine, ssh user@192.168.1.2), then you should be able to clone via SSH, like Josiah wrote:

git clone git+ssh://hap@192.168.1.2/~/working

If you want to continue to fetch / push between machines, you should configure public key authentication for SSH, to not have to provide password on each fetch.


If you don't have sshd installed on the source machine, you can clone using "smart" HTTP protocol if you have a web server installed and can install CGI scripts (see git-http-backend manpage), or you can clone using "dumb" HTTP protocol if you have web server installed, but can only serve static files (you would need to run git update-server-info in source repository first), or you can clone using rsync if you have it installed.

As a last resort, you can use "git bundle" to create an archive which you can move, for example, using a USB pendrive and clone from it.

Community
  • 1
  • 1
Jakub Narębski
  • 309,089
  • 65
  • 217
  • 230
0

In my case, I was ok with the following command.

git clone ssh://git@<ip address>/PATH/TO/REMOTE/REPO
Htet Phyo Naing
  • 464
  • 7
  • 20