Git clone without .git directory

后端 未结 4 1469
离开以前
离开以前 2020-12-02 04:39

Is there a flag to pass to git when doing a clone, say don\'t clone the .git directory? If not, how about a flag to delete the .git di

相关标签:
4条回答
  • 2020-12-02 05:22

    Alternatively, if you have Node.js installed, you can use the following command:

    npx degit GIT_REPO

    npx comes with Node, and it allows you to run binary node-based packages without installing them first (alternatively, you can first install degit globally using npm i -g degit).

    Degit is a tool created by Rich Harris, the creator of Svelte and Rollup, which he uses to quickly create a new project by cloning a repository without keeping the git folder. But it can also be used to clone any repo once...

    0 讨论(0)
  • 2020-12-02 05:25

    Use

    git clone --depth=1 --branch=master git://someserver/somerepo dirformynewrepo
    rm -rf ./dirformynewrepo/.git
    
    • The depth option will make sure to copy the least bit of history possible to get that repo.
    • The branch option is optional and if not specified would get master.
    • The second line will make your directory dirformynewrepo not a Git repository any more.
    • If you're doing recursive submodule clone, the depth and branch parameter don't apply to the submodules.
    0 讨论(0)
  • 2020-12-02 05:29

    since you only want the files, you don't need to treat it as a git repo.

    rsync -rlp --exclude '.git' user@host:path/to/git/repo/ .
    

    and this only works with local path and remote ssh/rsync path, it may not work if the remote server only provides git:// or https:// access.

    0 讨论(0)
  • 2020-12-02 05:34

    You can always do

    git clone git://repo.org/fossproject.git && rm -rf fossproject/.git
    
    0 讨论(0)
提交回复
热议问题