UPDATE - Originally I somehow read "git LFS" in the content of your question; I must've been mentally translating "large file" to "LFS", because if you have "large files" in your repo, you should be using LFS. Now I see that you just kinda-sorta mention LFS in your update, so maybe you've been using it and maybe you haven't.
Answer adjusted accordingly:
Not only is this possible, it is basic functionality of git lfs.
If you haven't been using lfs, then transitioning to it can be a bit of a problem, as it requires a rewrite of your repo's history. Your update can be read to suggest that you could just substitute a link in place of a file in the content of a repo; you cannot. git
won't do it, and if you use non-git
tools to fake it then you will be left with a corrupt repo. The storage in git
is "content-addressable", which means a few things... but what's notable here is, it means the content is an integral part of the storage structure.
There are tools that support this type of rewrite - a dedicated lfs migraiton tool, as well as an LFS mode in the BFG repo cleaner. Last I checked, each had its quirks. More importantly, the rewrite will be like a giant upstream rebase messing up the branches of everyone who had cloned the original repo.
So... it's a good practice and worht thinking about, but maybe not something you can do for this repo (unless you were already using LFS). There are still options, contrary to what the comments would have you believe. So here's a bit about LFS, then a bit about doing without LFS...
Using LFS
There are several lfs-specific configuration values that help determine what should be kept in the local storage. Basically the values will help you define what a "recent branch" and a "recent commit" are, and then lfs will locally cache objects needed for recent commits on recent branches.
See the documentation for git lfs prune
, as well as the --prune
option of git lfs fetch
, for details.
Without LFS
You could use a "shallow clone". Only newer versions of git provide good support for it, so you might have to upgrade. And you'll have to periodically "re-shallow" your history. And any given version is either "in" or "out" - there's no "past this age, drop the big files". That's the sort of thing that specifically requires the techniques LFS uses.
See the --depth
and --shallow-*
options of git clone
for details on what you can do and how.