Is there a way to work with a git repo completely remotely via git CLI?

Viewed 63

I do a lot of work which requires me to clone a new repository and use git to search for specific commits, find out which tag/release a specific commit belongs to, dig up when and where a specific bug was fixed, and so on...

The common thread here is that I rarely need to actually commit or write anything. Right now, my workflow consists of performing a git clone and then doing this locally.

This consumes time to download the repo, and uses space up locally. I can access most of the same info usually via a web UI, but web UIs are not my preference, can be unwieldly and slow, and so on....

Is there a way to do these types of operations without making a local copy using the git command line tool? I feel that local copies were intended for making changes to code, which I don't do for most of my work.

I'm typically interacting with remote repositories stored on GitHub or other public git servers (such as https://sourceware.org/git/?p=binutils.git;a=summary for example). I run Fedora 31.

1 Answers

If your source is major public repositories, then you don't really have much of a choice but to clone the repositories. GitHub provides an API, and there may be FUSE-based file systems which can mock a real repository, but neither of those are going to be performant, and if you need the Git CLI, then you need a repository.

There is a relatively new option which may decrease your need for disk space at the cost of a network connection: partial clone. You can clone a repository without any of the blobs by using the --filter=blob:none argument to git clone. That will download all of the commits and trees, which usually aren't very large, and fetch the blobs on demand from the remote as you need them.

If you decide to do this, you should be aware of a few things. One, you should use a reasonably recent Git. I'd really recommend rebuilding the Fedora 33 or Rawhide package here, since partial clone is relatively new and a decent number of bugs are fixed in each version. You can also build your own Git, but even as a Git developer, I just use the Debian experimental packages for daily use.

Second, partial clone requires support from the server side. GitHub has this, but not all hosting providers do. You may find the server side doesn't support it, in which case you'll just have to fall back to a regular clone, or possible a shallow clone if that meets your needs.

Related