# Git LFS

> Keep large files in a CloudRepo Git LFS repository. Point Git LFS at it once, and git push, git clone and git lfs pull work as always.

Keep your big files, such as game art, design files, models and datasets, in a CloudRepo Git LFS repository. Your code stays where it is today, on GitHub, GitLab, Bitbucket or your own Git server. Only the large files move to CloudRepo, and `git push`, `git clone` and `git lfs pull` work as they always do.

## Before you start

- A **Git LFS** repository. If you have none, see [Create Your First Repository](/docs/get-started/first-repository.html) and choose **Git LFS**.
- A repository token with **Download and publish packages** access to it, from [Repository Tokens: Create One and Authenticate](/docs/authenticate/repository-tokens.html). The username is the email address of the account that created the token, and the password is the token.
- Git with Git LFS installed. Run this once on each machine:

**Terminal**

```bash
git lfs install
```

## Point Git LFS at CloudRepo

**1. Give Git LFS your token.** Git LFS reads it from `~/.netrc`:

`~/.netrc`

```ini
machine your-org.mycloudrepo.io
login you@example.com
password YOUR_REPOSITORY_TOKEN
```

Keep the file readable by you alone: `chmod 600 ~/.netrc`. Git LFS also uses the credential helper Git already uses, so you can store the token there instead.

**2. Point your repository at CloudRepo.** In your repository, save the address in `.lfsconfig`. You commit this file, so everyone who clones the repository uses CloudRepo too. The second line has Git LFS send your token from the first request, so each large file is uploaded once:

**Terminal**

```bash
git config -f .lfsconfig lfs.url https://your-org.mycloudrepo.io/repositories/your-repo/info/lfs
git config -f .lfsconfig lfs.https://your-org.mycloudrepo.io/repositories/your-repo/info/lfs.access basic
```

## Push your large files

**3. Choose the files Git LFS keeps.** This tracks every Photoshop file:

**Terminal**

```bash
git lfs track "*.psd"
```

**4. Commit and push as usual.** Here `art/hero.psd` stands for your large file:

**Terminal**

```bash
git add .gitattributes .lfsconfig art/hero.psd
git commit -m "Store Photoshop files in Git LFS on CloudRepo"
git push
```

Expected: before Git pushes your commit, Git LFS uploads the file to CloudRepo and prints `Uploading LFS objects: 100% (1/1)`. Your Git host stores only a small pointer to it.

## Get the files back

A teammate who clones the repository gets the files from CloudRepo, as long as their `~/.netrc` holds a token too. In a clone made before the files were added, fetch them with:

**Terminal**

```bash
git lfs pull
```

## Limits

- One file is at most 50 GB.
- Git LFS asks for at most 300 files at a time. It asks for 100 unless you raise `lfs.transfer.batchSize`.
- CloudRepo stores each file once, by its SHA-256, and never replaces it. A file whose bytes do not match its pointer is refused, and nothing is stored.
- File locking (`git lfs lock`) is not available yet. Pushes are never held waiting for a lock.
- A Git LFS repository is always private. Every call needs your token.

> **Note:** CloudRepo keeps the large files. Your commits, branches and pull requests stay on your Git host.

## Moving from GitHub, GitLab or Artifactory

Run these in an up-to-date clone of your repository, while Git LFS there still uses your old server.

**1. Fetch every file from your old server,** for every branch and tag:

**Terminal**

```bash
git lfs fetch --all
```

**2. Point this clone at CloudRepo.** The first two lines are step 2 above. The third saves the address in this clone’s own Git config too, because an `lfs.url` set there or in your global Git config wins over `.lfsconfig`, and Git LFS would send your files back to the old server:

**Terminal**

```bash
git config -f .lfsconfig lfs.url https://your-org.mycloudrepo.io/repositories/your-repo/info/lfs
git config -f .lfsconfig lfs.https://your-org.mycloudrepo.io/repositories/your-repo/info/lfs.access basic
git config lfs.url https://your-org.mycloudrepo.io/repositories/your-repo/info/lfs
git lfs env
```

Expected: `git lfs env` prints `Endpoint=https://your-org.mycloudrepo.io/repositories/your-repo/info/lfs (auth=basic)`.

**3. Upload every file, then share the address.** `git lfs push --all` on its own uploads only what your local branches use, so the first line hands it every branch and tag, your Git host’s too. Committing `.lfsconfig` moves your team to CloudRepo:

**Terminal**

```bash
git for-each-ref --format='%(refname)' | git lfs push --all --stdin origin
git add .lfsconfig
git commit -m "Keep large files on CloudRepo"
git push
```

**4. Check that CloudRepo has every file.** This downloads them all again, from CloudRepo alone, into a spare folder, `.git/lfs-check`, and stops with an error naming any file CloudRepo does not have. Delete the folder afterwards:

**Terminal**

```bash
git -c lfs.storage=lfs-check lfs fetch --all
```

Before you shut the old server down, run `git lfs env` in each clone your team uses and check that it shows your CloudRepo address; a clone that still shows the old one needs the third line of step 2. Nothing else in your repository changes.

---

The page: https://www.cloudrepo.io/docs/formats/git-lfs.html
