Re: git download
- From
Sean Allred <allred.sean@gmail.com>
- Date
- Nov 24, 2022, 16:52 UTC
- Message-ID
- <87zgcgs2ne.fsf@gmail.com>
- In-Reply-To
- <CACtGy4i7Jv+UyjwKOLsMOQwUO81=o98AA5SNwi+=xUB76ehD_g@mail.gmail.com>
Vasilij Demyanov <qvasic@gmail.com> writes:
> I have a need to get just one file from a repository, it would be > useful to have a command something like this: > > git download repo_url branch_or_commit path/to/file
My immediate thought was git-archive[1], but depending the specifics of your needs/setup, you could use curl/wget for this pretty simply. For example, if you're using GitHub, you can
curl https://raw.githubusercontent.com/git/git/master/README.md
to dump the content of the README to standard out. As another example, to get the content of next:builtin/var.c,
curl https://raw.githubusercontent.com/git/git/next/builtin/var.c
The general pattern:
https://raw.githubusercontent.com/<repo>/<branch-or-commit>/<file-path>
GitLab's pattern is similar:
https://gitlab.com/<repo>/-/raw/<branch-or-commit>/<file-path>
e.g.
curl https://gitlab.com/gitlab-org/git/-/raw/main/README.md
This will be limited to getting a single file at a time. If you want more, you can make more curl requests, but git-archive can give a whole directory or even the entire repo at a specific commit. Since git-archive outputs a tar/zip file, you'll want to combine it with your favorite decompression tool to get your content.
[1]: https://git-scm.com/docs/git-archive
-- Sean Allred