git clone through ssh

后端 未结 10 2109
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-12 08:47

I have a project on which I created a git repository:

$ cd myproject  
$ git init  
$ git add .  
$ git commit  

I the wanted to create a b

相关标签:
10条回答
  • 2020-12-12 08:56

    Disclaimer: This is just a copy of a comment by bobbaluba made more visible for future visitors. It helped me more than any other answer.


    You have to drop the ssh:// prefix when using git clone as an example

    git clone git@github.com:owner/repo.git
    
    0 讨论(0)
  • 2020-12-12 08:56

    I did : git clone --bare "/GITREPOSITORIES/RepoA" "ssh://luc@EERSTENASDS119J/volume1/RepoA" Result : fatal: destination path 'ssh://luc@EERSTENASDS119J/volume1/RepoA' already exists and is not an empty directory.

    The system created a directory ssh://luc@EERSTENASDS119J/volume1/RepoA in my current path.

    So git clone did not interpret the URL specification. Used the workaround of Alec.

    0 讨论(0)
  • 2020-12-12 08:57

    I want to attempt an answer that includes git-flow, and three 'points' or use-cases, the git central repository, the local development and the production machine. This is not well tested.

    I am giving incredibly specific commands. Instead of saying <your folder>, I will say /root/git. The only place where I am changing the original command is replacing my specific server name with example.com. I will explain the folders purpose is so you can adjust it accordingly. Please let me know of any confusion and I will update the answer.

    The git version on the server is 1.7.1. The server is CentOS 6.3 (Final).

    The git version on the development machine is 1.8.1.1. This is Mac OS X 10.8.4.

    The central repository and the production machine are on the same machine.

    the central repository, which svn users can related to as 'server' is configured as follows. I have a folder /root/git where I keep all my git repositories. I want to create a git repository for a project I call 'flowers'.

    cd /root/git
    git clone --bare flowers flowers.git
    

    The git command gave two messages:

    Initialized empty Git repository in /root/git/flowers.git/
    warning: You appear to have cloned an empty repository.
    

    Nothing to worry about.

    On the development machine is configured as follows. I have a folder /home/kinjal/Sites where I put all my projects. I now want to get the central git repository.

    cd /home/kinjal/Sites
    git clone root@example.net:/root/git/flowers.git
    

    This gets me to a point where I can start adding stuff to it. I first set up git flow

    git flow init -d
    

    By default this is on branch develop. I add my code here, now. Then I need to commit to the central git repository.

    git add .
    git commit -am 'initial'
    git push
    

    At this point it pushed to the develop branch. I want to also add this to the master branch.

    git flow release start v0.0.0 develop
    git flow release finish v0.0.0
    git push
    

    Note that I did nothing between the release start and release finish. And when I did the release finish I was prompted to edit two files. This pushed the develop branch to master.

    On the production site, which is on the same machine as my central git repository, I want put the repository in /var/www/vhosts/example.net. I already have /var/www/vhosts.

    cd /var/www/vhosts
    git clone file:///root/git/flowers.git example.net
    

    If the production machine would also be on a different machine, the git clone command would look like the one used on the development machine.

    0 讨论(0)
  • 2020-12-12 09:00

    try this.

    Step 1:

    ls -al ~/.ssh
    

    Step 2:

    ssh-keygen 
    

    (using enter key for default value) Step 3: To setup config file

    vim /c/Users/Willie/.ssh/config
    

    Host gitlab.com
    HostName gitlab.com
    User git
    IdentityFile ~/.ssh/id_rsa

    Step 4:

    git clone git@gitlab.com:<username>/test2.git
    

    Step 5:
    When you finished Step 4
    1.the test2.git file will be download done
    2.you will get the new file(known_hosts) in the ~/.ssh

    PS: I create the id_rsa and id_rsa.ub by meself and I deliver it to the Gitlab server. using both keys to any client-sides(windows and Linux).

    0 讨论(0)
  • 2020-12-12 09:01

    You need to run the clone command on what you are calling the server. But I bet you are not running an ssh server on your local client so that won't work anyway. Suggest you follow this approach (check the manual 'cause I'm doing this from memory)

    1. Log into the server machine.
    2. Create a bare repo using git init --bare
    3. On the client machine you can push your repo to the server. git remote add origin ssh://user@server:/GitRepos/myproject.git followed by git push origin master
    0 讨论(0)
  • 2020-12-12 09:04

    This is possibly unrelated directly to the question; but one mistake I just made myself, and I see in the OP, is the URL specification ssh://user@server:/GitRepos/myproject.git - namely, you have both a colon :, and a forward slash / after it signifying an absolute path.

    I then found Git clone, ssh: Could not resolve hostname – git , development – Nicolas Kuttler (as that was the error I was getting, on git version 1.7.9.5), noting:

    The problem with the command I used initially was that I tried to use an scp-like syntax.

    ... which was also my problem! So basically in git with ssh, you either use

    • ssh://username@host.xz/absolute/path/to/repo.git/ - just a forward slash for absolute path on server
    • username@host.xz:relative/path/to/repo.git/ - just a colon (it mustn't have the ssh:// for relative path on server (relative to home dir of username on server machine)

    Hope this helps someone,
    Cheers!

    0 讨论(0)
提交回复
热议问题