git clone from another directory

前端 未结 8 1895
一生所求
一生所求 2020-12-04 07:38

I am trying to clone repo from another directory.

Lets say I have one repo in C:/folder1 and C:/folder2

I want to clone the work in

相关标签:
8条回答
  • 2020-12-04 08:11
    cd /d c:\
    git clone C:\folder1 folder2
    

    From the documentation for git clone:

    For local repositories, also supported by git natively, the following syntaxes may be used:

    /path/to/repo.git/
    
    file:///path/to/repo.git/
    

    These two syntaxes are mostly equivalent, except the former implies --local option.

    0 讨论(0)
  • 2020-12-04 08:11

    None of these worked for me. I am using git-bash on windows. Found out the problem was with my file path formatting.

    WRONG:

    git clone F:\DEV\MY_REPO\.git
    

    CORRECT:

    git clone /F/DEV/MY_REPO/.git
    

    These commands are done from the folder you want the repo folder to appear in.

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

    Using the path itself didn't work for me.

    Here's what finally worked for me on MacOS:

    cd ~/projects
    git clone file:///Users/me/projects/myawesomerepo myawesomerepocopy
    

    This also worked:

    git clone file://localhost/Users/me/projects/myawesomerepo myawesomerepocopy
    

    The path itself worked if I did this:

    git clone --local myawesomerepo myawesomerepocopy
    
    0 讨论(0)
  • 2020-12-04 08:15

    It's as easy as it looks.

    14:27:05 ~$ mkdir gittests
    14:27:11 ~$ cd gittests/
    14:27:13 ~/gittests$ mkdir localrepo
    14:27:20 ~/gittests$ cd localrepo/
    14:27:21 ~/gittests/localrepo$ git init
    Initialized empty Git repository in /home/andwed/gittests/localrepo/.git/
    14:27:22 ~/gittests/localrepo (master #)$ cd ..
    14:27:35 ~/gittests$ git clone localrepo copyoflocalrepo
    Cloning into 'copyoflocalrepo'...
    warning: You appear to have cloned an empty repository.
    done.
    14:27:42 ~/gittests$ cd copyoflocalrepo/
    14:27:46 ~/gittests/copyoflocalrepo (master #)$ git status
    On branch master
    
    Initial commit
    
    nothing to commit (create/copy files and use "git add" to track)
    14:27:46 ~/gittests/copyoflocalrepo (master #)$ 
    
    0 讨论(0)
  • 2020-12-04 08:18

    It is worth mentioning that the command works similarly on Linux:

    git clone path/to/source/folder path/to/destination/folder
    
    0 讨论(0)
  • 2020-12-04 08:20

    In case you have space in your path, wrap it in double quotes:

    $ git clone "//serverName/New Folder/Target" f1/
    
    0 讨论(0)
提交回复
热议问题