Rajeev
Rajeev

Reputation: 46899

git clone repo to a remote machine

How do we clone a repo which is in the local directory to a remote mchine directory

 machine1:/usr/rep/  -> clone this to machine2:/var/new_repo

what is the actual command for this

EDIT1 I am trying to create the clone from machine1

EDIT2 I have also tried the following git clone --bare [email protected]/usr/repo /var/repo/ not sure whether its the right way to do it

EDIT3 This is the error after executing the command in EDIT2

You have no controlling tty and no DISPLAY. Cannot read passphrase. fatal: The remote end hung up unexpectedly 

================================================Initialized empty Git repository
in /var/repo/ DEBUG: remote_exec loop:$stderr: Initialized empty Git repository
in /var/repo/ DEBUG: create_repoX loop: $stdout: DEBUG: create_repoX loop: 
$stderr: Initialized empty Git repository in /var/repo/ DEBUG: create_repoX loop: $exit: 32768 

Upvotes: 9

Views: 12248

Answers (5)

DaveFX
DaveFX

Reputation: 495

If you don't have SSH access to either the origin git server or the target git server, these are the commands you should carry out:

  1. Check out the repository from your existing git host. Use the --mirror parameter:

    git clone --mirror <source-git-url> temp-dir
    
  2. Add the corresponding new repo as another remote in your local repository:

    cd temp-dir
    git remote add newrepo <target-git-url>
    
  3. Push the whole repo to the new location :

    git push --mirror newrepo
    
  4. Remove your temporary local repository:

    cd ..
    rm -rf temp-dir
    

Upvotes: 0

Robert Muil
Robert Muil

Reputation: 3085

I think there are legitimate reasons for 'pushing' a clone to a remote machine as opposed to running the clone on the remote machine itself, which I don't see covered by the other answers here. In fact, I have had reason to do this a number of times.

I wrote a script to handle it easily: git-pushclone

Description: The script clones a repository to a remote server and makes this new repository a remote repository of the current one. SSH protocol is used.

This implements a push-style of cloning, which is necessary whenever one does not want to clone from the remote machine. Examples are:

  1. No incoming access to local server: When development has occurred on a local machine to which one does not wish to grant any remote access, but it is desired to 'publish' the development to a server from which others can then get access.

  2. A communal login to remote server: When one does not have individual access to the remote server but can only login as a group user: in this case, initiating a clone from the remote server would require putting credentials for the local repository server in the group account of the server.

Upvotes: 8

Attila Fulop
Attila Fulop

Reputation: 7011

git clone ssh://[email protected]/usr/repo /var/repo/

I mean ssh user@host "git clone ssh://[email protected]/usr/repo /var/repo/"

Upvotes: 0

KingCrunch
KingCrunch

Reputation: 131811

Pass the command to ssh and clone the repository from machine2

ssh machine2 'git clone machine1:/path/to/repo /local/path/to/new/repo'

You need a ssh-server on machine1. However, you can even just copy the whole folder, because in git the repository is just a folder, thus copying it, will copy the repository.

scp -r /path/to/repo machine2:/var/new_repo

Upvotes: 1

ThiefMaster
ThiefMaster

Reputation: 318468

You don't. You run git clone on the remote machine and clone from machine1. If that's not possible, simply clone it locally on machine 1 and copy the whole folder to machine2.

Upvotes: -1

Related Questions