jamell.dev

You can fetch a single file from a remote git repo without cloning

2026-02-25 (7m ago)2 views

#git#cli

I needed to check pom.xml in about 10 different repos and cloning all of them felt really wasteful. Turns out there's a much better way:

git archive --remote="ssh://git@host/project/repo.git" HEAD path/to/file.txt \
  | tar -xO

Here's what each part does:

The whole thing is one round-trip and prints the file contents straight to your terminal. No disk usage, no cleanup. I thought that was really cool.

One thing to watch out for: the server needs uploadArchive enabled. If it's disabled you'll get an error, or sometimes just silence.