Skip to content

Git LFS Client Setup

Refringe edited this page Oct 26, 2026 · 3 revisions

Git LFS Client Setup

This page explains how to configure Git LFS clients to use your Anchor LFS server.

For Contributors

When the repository already commits an .lfsconfig that points at Anchor LFS, this is all you need:

  1. Install Git LFS and run git lfs install (see Prerequisites).
  2. Clone the repository. Its .lfsconfig sets the server URL, which git lfs env shows on the Endpoint= line.
  3. Create a GitHub Personal Access Token with the permissions in Token Permissions.
  4. Push, lock a file, or download from a private endpoint. When Git asks for a username and password, enter your GitHub username and the token. A credential helper saves them, so Git asks only once.
  5. If .lfsconfig does not set locksverify, your first push prints Locking support detected on remote "origin" and a git config command. Run it, so that a push changing a file someone else has locked stops instead of only warning.

Prerequisites

Install Git LFS if you haven't already:

# macOS
brew install git-lfs

# Ubuntu/Debian
sudo apt install git-lfs

# Windows (via Chocolatey)
choco install git-lfs

# Then initialise (once per user)
git lfs install

Pointing Git LFS to Your Server

Per-Repository (.lfsconfig)

The recommended approach is to add an .lfsconfig file to your repository root. This ensures all contributors use the same LFS server:

[lfs]
	url = https://lfs.example.com/org/repo
	locksverify = true

Create it with git config, which writes the same file in every shell and on Windows, then commit it:

git config -f .lfsconfig lfs.url https://lfs.example.com/org/repo
git config -f .lfsconfig lfs.locksverify true
git add .lfsconfig
git commit -m "Configure LFS server"

locksverify = true makes every contributor's push stop when it changes a file someone else has locked, or when the server cannot check locks. Without it, Git LFS only prints a warning and pushes anyway.

Per-Repository (Git Config)

Alternatively, set the URL via Git config (this is local to your clone and not shared):

git config lfs.url https://lfs.example.com/org/repo

Note: The endpoint path in the URL (e.g., /org/repo) must match the endpoint value configured in your Anchor LFS config.toml. Each repository has its own endpoint, so set lfs.url per repository, never with --global.

Authentication

When GitHub authentication is enabled on the endpoint, Git LFS needs credentials. The password should be a GitHub Personal Access Token (PAT).

Token Permissions

  • Classic token: the repo scope, or public_repo to upload to public repositories only.
  • Fine-grained token: under Repository access, include the repository. Under Repository permissions, set Contents to Read-only to download from a private endpoint, or Read and write to upload and lock files. GitHub adds Metadata: Read-only, which the server needs to look up the repository.

If the organisation enforces SAML single sign-on, authorise the token for it, or the server answers 403.

The server ignores the username Git sends. It asks GitHub for the token's login and records that as the owner of your locks, so a different username changes nothing. Credential helpers still store one, so use your GitHub username.

Using Git Credential Helpers

Git LFS uses Git's credential system. The simplest setup:

# Store credentials (they will be saved by your credential helper)
git credential approve <<EOF
protocol=https
host=lfs.example.com
username=your-github-username
password=ghp_your_personal_access_token
EOF

Using .netrc

Create or edit ~/.netrc (or ~/_netrc on Windows):

machine lfs.example.com
login your-github-username
password ghp_your_personal_access_token

Secure the file:

chmod 600 ~/.netrc

Using Environment Variables

Git LFS can pick up credentials from the GIT_ASKPASS program or credential helpers. Refer to the Git credential documentation for advanced setups.

Endpoints Without Authentication

An endpoint with authentication = "none" never answers 401, so Git LFS sends it no credentials. Every lock is then owned by anonymous, and anyone who can reach the endpoint can release any lock.

To label your locks with a name, tell Git LFS to send credentials to the endpoint:

git config lfs.https://lfs.example.com/org/repo.access basic

Git then asks for a username and password, and your credential helper saves them. The server records the username as the lock owner without checking it and ignores the password, so this labels locks but does not protect them.

Tracking Files with Git LFS

Configure which files should be stored in LFS:

# Track by extension
git lfs track "*.psd"
git lfs track "*.zip"
git lfs track "*.bin"

# Track by path
git lfs track "assets/large/**"

# View tracked patterns
git lfs track

This updates .gitattributes, which should be committed:

git add .gitattributes
git commit -m "Track large files with LFS"

Common Operations

Push LFS Objects

# Normal push; LFS objects are uploaded automatically
git push origin main

Pull LFS Objects

# Normal pull; LFS objects are downloaded automatically
git pull

# Or fetch LFS objects explicitly
git lfs pull

Check LFS Status

# Show LFS objects in the current checkout
git lfs ls-files

# Show LFS status
git lfs status

File Locking

Anchor LFS supports the Git LFS file locking API:

# Lock a file before editing
git lfs lock assets/model.bin

# List current locks
git lfs locks

# Unlock when done
git lfs unlock assets/model.bin

# Force unlock (override someone else's lock)
git lfs unlock --force assets/model.bin

See File Locking for more details.

Verifying Connectivity

Test that your client can reach the server:

# Check server health
curl https://lfs.example.com/health

# Test LFS environment
git lfs env

The git lfs env command shows the configured LFS endpoint and credential helper, which is useful for debugging.

Next Steps

Clone this wiki locally

⌂ 换网址