Skip to content

Download files and directories locally from a remote git repository

License

Notifications You must be signed in to change notification settings

cedricium/gitdl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gitdl ↯

Download files and directories locally from a remote git repository

Motivation

When updating my personal website, I needed a simple way to copy old blog posts and their assets from an archived repository to the new working repository. I didn't care about the version control revisions of these posts (most were never edited after being created anyways), and I didn't want to have to clone the entire archived repository and manually mv files/directories around.

Inspired by the Unix philosophy of building simple programs that do one thing well like cp and ftp, I envisioned a simple CLI interface to copy files and directories from a remote git repository to one's local filesystem. Since I was learning Go at the time, the language seemed like a perfect candidate to utilize for this project.

Description

gitdl REPO SOURCE[…] DEST_DIR
  • REPO: short GitHub path <owner>/<repo> (e.g. cedricium/gitdl)
  • SOURCE: file(s) and/or director(y|ies) from REPO wanting to download
  • DEST_DIR: local destination directory where SOURCE args are copied to

Examples

The initial use-case that inspired development of gitdl:

gitdl cedricium/personal-site {posts,public/blog-assets} ~/git/website

Development

Important

Requires Go v1.16+ since go mod is used to manage dependencies.

Implementation

Three ways to approach the problem of downloading remote repository contents locally:

  1. Using GitHub API to download desired files
  2. Downloading archive of repository (tarball), unpacking and moving desired files
  3. Utilizing advanced git operations to selectively fetch desired files

Limitations/Assumptions

To keep the API for this program simple initially, some assumptions were made, which might be limitations for some users. Those are listed below but requests or contributions to amend these are welcome (possible changes noted in parenthesis):

  • GitHub is the only supported git host (-h, -host option for e.g. BitBucket, GitLab, etc.)
  • when checking out the git repository, the default branch/HEAD ref is used (-b, -branch option)
  • public access is required to the repository (auth mechanism, e.g. token, user/password, ssh key)

License

MIT License

About

Download files and directories locally from a remote git repository

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages