Website/content/docs/infrastructure/forgejo/git-lfs.md

42 lines
1.7 KiB
Markdown
Raw Normal View History

2024-03-03 23:20:22 +01:00
---
title: 'Git LFS'
date: 2024-03-03T22:42:25+01:00
---
As I'm working with quite a few binary[^1] files, such as `.jpg` images, `.mp3`
tracks and `.mp4` videos, `.pdf` documents, and `.zip` archives, it's a best
practice to use [Git LFS](https://git-lfs.com/) for versioning those files. The
initial user setup and instructions on how to use Git LFS for a new repository
is described at the project website. However, in my case I need to migrate some
exisiting files from plain Git to be tracked by Git LFS.
## Git LFS migration
Though the [official tutorial](https://github.com/git-lfs/git-lfs/wiki/Tutorial)
expands on *adding git-lfs to a pre-existing repo* the approach seems to be very
complicated. For this reason, I rather follow the approach described in a DevOps
[blog post](https://josh-ops.com/posts/migrate-to-git-lfs/). And to tell a long
story short, it's just a matter of these four commands:
```bash
cd ~/git-repo-with-large-files
git lfs migrate import --include="*.jpg, *.mp3, *.mp4, *.pdf, *.zip" --everything
git lfs ls-files # list the newly tracked LFS files
git push --all --force # force push all branches to remote
```
Note: If you are going to use different binary file types, you have to adapt the
glob[^2] pattern parameters in the `--include` option.
2024-03-04 00:00:04 +01:00
{{< callout type="warning" >}}
By using the `--everything` option the tracked files may be replaced by a
placeholder pointer, which seems like they are broken. In this case, execute:
```bash
git lfs checkout
```
{{< /callout >}}
2024-03-03 23:20:22 +01:00
[^1]: [Binary file](https://en.wikipedia.org/wiki/Binary_file) in the Wikipedia
[^2]: The [glob](https://www.man7.org/linux/man-pages/man7/glob.7.html) Linux man
page