SSH and Git Clone

2019-08-01 19:49发布

问题:

Is it possible to ssh to a remote server and trigger a git clone. ie I need to ssh to server A, create a folder /tmp/A and clone a repository with all its contents on A. The ssh keys of the remote servers are configured to connect to git.

ssh root@Server 
git init
git clone gitproject.

This doesn't work. Any help is appreciated. I feel the script steps are run asynchronously and thus the clone fails with .git not found.

回答1:

You said: "I feel the script steps are run asynchronously", this indicates you are doing all this in a script and therefore your git init and git clone are done local. You won't actually need git init here.

Clone the repository remotely on the server

ssh root@server 'git clone gitproject /tmp/A'

to issue the command on the server and have it cloned there.