Generally useful Git subcommands for working with Git LFS.
These tools were written along with the miniseries of articles about
Git LFS on mslinn.com.
All commands can be invoked as Git subcommands (e.g., git ls-files, git nonlfs):
git-delete-github-repo- Deletes the given GitHub repo without prompting (requiresghCLI)git-giftless- Run Giftless Git LFS server (requires Python with giftless and uwsgi)git-lfs-trace- Git LFS transfer adapter that reports activity between Git client and LFS servergit-ls-files- Frontend forgit ls-fileswith pattern permutationgit-lfs-files- Frontend forgit lfs ls-fileswith pattern permutationgit-lfs-track- Frontend forgit lfs trackwith pattern permutationgit-lfs-untrack- Frontend forgit lfs untrackwith pattern permutationgit-new-bare-repo- Creates a bare Git repositorygit-nonlfs- Lists files that are not in Git LFSgit-unmigrate- Reversesgit lfs migrate importfor given wildmatch patterns
- Go 1.18 or later
- Git
- For
git-giftless: Python 3 withgiftlessanduwsgiinstalled - For
git-delete-github-repo: GitHub CLI (gh)
# Clone the repository
git clone https://github.com/mslinn/git_lfs_scripts.git
cd git_lfs_scripts
# Build all binaries
make build
# Install to ~/.local/bin (default)
make install
# Or install to a custom location
make install INSTALL_DIR=/usr/local/binMake sure the installation directory is in your PATH. For ~/.local/bin:
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrcAlternatively, you can install individual commands directly:
go install github.com/mslinn/git_lfs_scripts/cmd/git-ls-files@latest
go install github.com/mslinn/git_lfs_scripts/cmd/git-nonlfs@latest
# etc.These commands expand file extension patterns for convenience:
# Track all PDF files (current directory only)
git lfs-track pdf
# Track all MP3 files in upper and lower case (everywhere)
git lfs-track -ce mp3
# Dry run to see what would be tracked
git lfs-track -dce mp3 mp4
# Flags can be combined or separate
git lfs-track -d -c -e mp3 # Same as -dce
# Long flag names are also supported
git lfs-track --dryrun --bothcases --everywhere mp3
# List all files not tracked by LFS
git nonlfs
# Unmigrate files from LFS back to Git
git unmigrate -ce mp3Commands that support pattern permutation (git-ls-files, git-lfs-files, git-lfs-track, git-lfs-untrack) support:
-c,--bothcases- Expand pattern to upper and lower case (useful for media files)-d,--dryrun- Show what would be done without executing-e,--everywhere- Apply pattern recursively in all directories-h,--help- Show help message
Flags can be combined (e.g., -dce) or used separately (e.g., -d -c -e).
# Start Giftless LFS server
git giftless --port 8080 --workers 4
# Create a new bare repository
git new-bare-repo /path/to/repo.git
# Delete a GitHub repository
git delete-github-repo my-test-repoTo use the LFS trace adapter, configure it in your Git LFS config:
git config lfs.customtransfer.trace.path `which git-lfs-trace`The above adds something similar to the following to the current Git repository configuration
(.git/config)
[lfs "customtransfer.trace"]
path = /home/mslinn/go/bin/git-lfs-trace
make build # Build all binaries
make test # Run tests
make clean # Clean build artifacts
make tidy # Tidy go.mod.
├── cmd/ # Command implementations
│ ├── git-ls-files/
│ ├── git-lfs-files/
│ ├── git-lfs-track/
│ ├── git-lfs-untrack/
│ ├── git-lfs-trace/
│ ├── git-nonlfs/
│ ├── git-unmigrate/
│ ├── git-new-bare-repo/
│ ├── git-delete-github-repo/
│ └── git-giftless/
├── internal/ # Shared internal packages
│ ├── common/ # Common utilities
│ ├── lfsfiles/ # Pattern permutation logic
│ └── github/ # GitHub operations
├── Makefile # Build automation
└── README.md # This file