Git Clone: Just the files, please?

后端 未结 8 691
北海茫月
北海茫月 2021-01-30 00:25

I want to clone a GIT repo and NOT end up with a .git directory. In other words I just want the files. Is there a way to do this?

git clone --no-chec

8条回答
  •  一个人的身影
    2021-01-30 01:08

    git checkout -f

    There's another way to do this by splitting the repo from the working tree.

    This method is useful if you need to update these git-less git files on a regular basis. For instance, I use it when I need to check out source files and build an artifact, then copy the artifact into a different repo just for deployment to a server, and I also use it when pushing source code to a server when I want the source code to checkout and build into the www directory.

    We'll make two folders, one for the git one for the working files:

    mkdir workingfiles
    mkdir barerepo.git
    

    initialize a bare git repo:

    cd barerepo.git
    git --bare init 
    

    Then create a post-receive hook:

    touch hooks/post-receive
    chmod ug+x hooks/post-receive
    

    Edit post-receive in your favorite editor:

    GIT_WORK_TREE=/path/to/workingfiles git checkout -f
    # optional stuff:
    cd down/to/some/directory
    [do some stuff]
    

    Add this as a remote:

    git remote add myserver ssh://user@host:/path/to/barerepo.git
    

    Now every time you push to this bare repo it will checkout the working tree to /workingfiles/. But /workingfiles/ itself is not under version control; running git status in /workingfiles/ will give the error fatal: Not a git repository (or any parent up to mount point /data). It's just plain files.

    Unlike other solutions rm -r .git command is not needed, so if /workingfiles/ is some other git repo you don't have to worry about the command used removing the other repo's git files.

提交回复
热议问题