Skip to content

Instantly share code, notes, and snippets.

@divs1210
Last active July 10, 2021 22:45
Show Gist options
  • Save divs1210/973493941a82b28f0d4a to your computer and use it in GitHub Desktop.
Save divs1210/973493941a82b28f0d4a to your computer and use it in GitHub Desktop.
Download a specific folder from a github repo
#!/usr/bin/python
"""
Download a specific folder from a github repo:
gitget.py https://github.com/divs1210/kilvish/tree/master/examples/bricksnball
"""
__author__ = 'Divyansh Prakash'
import sys
import subprocess
if __name__ == '__main__':
if len(sys.argv) > 1:
github_src = sys.argv[1]
try:
head, branch_etc = github_src.split('/tree/')
folder_url = '/'.join(branch_etc.split('/')[1:])
except:
print 'err:\tnot a valid folder url!'
else:
print 'fetching...'
subprocess.call(['svn', 'checkout', '/'.join([head, 'trunk', folder_url])])
else:
print 'use:\tgitget.py https://github.com/user/project/tree/branch-name/folder\n'
@hendisantika
Copy link

Can You give more details how to use this script?
Thank You.

@YunLambert
Copy link

Can You give more details how to use this script?
Thank You.

The author used subprocess to call svn which is an another version control system. So you may need to install svn first?
And in this script, it actually uses svn checkout URL[@REV]... [PATH] to download one specify folder on github, the doc is here:http://svn.gnu.org.ua/svnbook/svn.ref.svn.c.checkout.html

@divs1210
Copy link
Author

divs1210 commented Mar 5, 2020

Usage: gitget.py https://github.com/<account-name>/<project-name>/tree/master/<path-to-folder>

@dotiful
Copy link

dotiful commented Jun 16, 2020

@divs1210 how to delete .svn subfolder after download?
thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment