Clone contents of a GitHub repository (without the folder itself)

前端 未结 6 1247
梦谈多话
梦谈多话 2020-12-04 04:57

I\'d like to git clone the contents of a repository I have on GitHub. When I git clone (git@github:me/name.git...) I get a folder called name

相关标签:
6条回答
  • 2020-12-04 05:27

    Unfortunately, this doesn't work if there are other, non-related directories already in the same dir. Looking for a solution. The error message is: "fatal: destination path '.' already exists...".

    The solution in this case is:

    git init
    git remote add origin git@github.com:me/name.git
    git pull origin master
    

    This recipe works even if there are other directories in the one you want to checkout in.

    0 讨论(0)
  • 2020-12-04 05:29

    You can specify the destination directory as second parameter of the git clone command, so you can do:

    git clone <remote> .
    

    This will clone the repository directly in the current local directory.

    0 讨论(0)
  • 2020-12-04 05:30

    If the folder is not empty, a slightly modified version of @JohnLittle's answer worked for me:

    git init
    git remote add origin https://github.com/me/name.git
    git pull origin master
    

    As @peter-cordes pointed out, the only difference is using https protocol instead of git, for which you need to have SSH keys configured.

    0 讨论(0)
  • 2020-12-04 05:30

    to clone git repo into the current and empty folder (no git init) and if you do not use ssh:

    git clone https://github.com/accountName/repoName.git .
    
    0 讨论(0)
  • 2020-12-04 05:36

    If the current directory is empty, you can do that with:

    git clone git@github:me/name.git .
    

    (Note the . at the end to specify the current directory.) Of course, this also creates the .git directory in your current folder, not just the source code from your project.

    This optional [directory] parameter is documented in the git clone manual page, which points out that cloning into an existing directory is only allowed if that directory is empty.

    0 讨论(0)
  • 2020-12-04 05:39

    this worker for me

    git clone <repository> .
    
    0 讨论(0)
提交回复
热议问题