Reputation: 46899
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
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:
Check out the repository from your existing git host. Use the --mirror parameter:
git clone --mirror <source-git-url> temp-dir
Add the corresponding new repo as another remote in your local repository:
cd temp-dir
git remote add newrepo <target-git-url>
Push the whole repo to the new location :
git push --mirror newrepo
Remove your temporary local repository:
cd ..
rm -rf temp-dir
Upvotes: 0
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:
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.
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
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
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
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