git export from github remote repository

前端 未结 10 1196
北恋
北恋 2020-12-07 13:50

I\'d like to export from github remote repository, not cloning it. Similar to svn export, I do not want to get .git folder with it. I can work around it by cloning and remov

相关标签:
10条回答
  • 2020-12-07 14:45

    For a normal export:

    $ git archive master | tar -x -C /path/to/destination
    

    For a zip archive:

    $ git archive --format zip --output /path/to/destination/file.zip master
    

    Of course for this to work, you'll need to clone it locally first, there's no clean way around that.

    0 讨论(0)
  • 2020-12-07 14:47

    One way to achieve this is to use the SVN support offered by GIT.

    Steps to perform as root one off are (for Cent os);

    yum install git
    
    yum install subversion
    

    Then to do a selective export the following syntax should be used:

    svn export  <git repository>/<source folder> <empty target folder>  --no-auth-cache --force --username <active directory username>
    

    If you do not use parameter --no-auth-cache when prompted to save the password type "no" for security reasons, or it will be saved unencrypted.

    When translating from the GIT notation to the SVN notation the following mapping applies; replace "tree/master" with "trunk" for master replace "tree/branch_name" with "branches/branch_name" for branches

    This works for both files and directories.

    0 讨论(0)
  • 2020-12-07 14:49

    Thanks to the Subversion support by GitHub, you can use svn export to get the project without any version control files:

    svn export https://github.com/user/project/trunk
    

    Notice the URL format:

    • The base URL is https://github.com/
    • USERNAME/PROJECTNAME without .git
    • /trunk appended at the end

    This way you can get branches and subdirectories too.

    This creates a directory with the exported files. It's not possible to create a tar/zip directly, you have to do in two steps (export + zip). This is a limitation of svn export itself.

    As @Jon pointed out, this will create the export in a directory named trunk by default. You can specify a different name if you prefer:

    svn export https://github.com/username/projectname/trunk projectname
    

    You can use this technique to export any sub-directory of the project. For example if you want only some/path, you can do:

    svn export https://github.com/username/projectname/trunk/some/path local-dir-name
    

    You can get paths from branches and tags too. The endpoint https://github.com/username/projectname behaves fully as a Subversion repository with a regular layout, so you will find branches in https://github.com/username/projectname/branches and tags in https://github.com/username/projectname/tags.

    Before you export something large by mistake, it's good to check first the content of the path. You can do that using svn ls, for example:

    svn ls https://github.com/username/projectname/
    

    Normally this should give you:

    branches/
    tags/
    trunk/
    

    You could iteratively explore the repository this way.

    0 讨论(0)
  • 2020-12-07 14:49

    If your goal is to limit the quantity of information exchanged with the server, have you considered using clone with --depth? You would still need to remove the (much reduced) .git subdirectory though:

    git clone --depth=1 git@github.com:xxx/yyy.git && rm -rf yyy/.git
    
    0 讨论(0)
提交回复
热议问题