git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

Previous: Jacob KellerNext: ZheNing Hu
Message 3 of 4 in “git download”
  1. Vasilij DemyanovNov 23, 2022
  2. Jacob KellerNov 23, 2022
  3. Sean AllredNov 24, 2022
  4. ZheNing HuNov 25, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.