Git basics

Store big files with Git LFS

Keep big files like videos, images and datasets out of your normal Git history with Git LFS, so cloning and pushing stay fast.

Fill these in once
  1. Install Git LFS
    Terminal
    brew install git-lfs

    This uses Homebrew.

  2. Turn on Git LFS for your user
    Terminal
    git lfs install

    You only do this once per computer.

  3. Tell Git LFS which files to handle
    Terminal
    git lfs track "*.psd"

    Run this inside your project. It writes the pattern to a file called .gitattributes. Use quotes so your shell does not expand the pattern.

  4. Commit the tracking rule
    Terminal
    git add .gitattributes && git commit -m "Track *.psd with Git LFS"
  5. Add and push big files as usual
    Terminal
    git add . && git commit -m "Add big files" && git push

    Git stores a small pointer in the repo and uploads the real file to the LFS storage on your host. Files committed before you ran track stay in normal Git history.

Check it worked

  1. See which patterns Git LFS tracks
    Terminal
    git lfs track
  2. List the files stored with Git LFS
    Terminal
    git lfs ls-files
Undo it
  1. Stop tracking a pattern
    Terminal
    git lfs untrack "*.psd"

    New files that match go back into normal Git. Commit .gitattributes afterwards. Files already pushed stay in LFS storage.

  2. Download the real files after cloning
    Terminal
    git lfs pull

    Use this if you see small text pointer files instead of your big files.

  1. Install Git LFS
    Terminal · Ubuntu / Debian
    sudo apt install git-lfs

    This is for Ubuntu and Debian. Other systems have git-lfs in their own package manager.

  2. Turn on Git LFS for your user
    Terminal · Ubuntu / Debian
    git lfs install

    You only do this once per computer.

  3. Tell Git LFS which files to handle
    Terminal · Ubuntu / Debian
    git lfs track "*.psd"

    Run this inside your project. It writes the pattern to a file called .gitattributes. Use quotes so your shell does not expand the pattern.

  4. Commit the tracking rule
    Terminal · Ubuntu / Debian
    git add .gitattributes && git commit -m "Track *.psd with Git LFS"
  5. Add and push big files as usual
    Terminal · Ubuntu / Debian
    git add . && git commit -m "Add big files" && git push

    Git stores a small pointer in the repo and uploads the real file to the LFS storage on your host. Files committed before you ran track stay in normal Git history.

Check it worked

  1. See which patterns Git LFS tracks
    Terminal · Ubuntu / Debian
    git lfs track
  2. List the files stored with Git LFS
    Terminal · Ubuntu / Debian
    git lfs ls-files
Undo it
  1. Stop tracking a pattern
    Terminal · Ubuntu / Debian
    git lfs untrack "*.psd"

    New files that match go back into normal Git. Commit .gitattributes afterwards. Files already pushed stay in LFS storage.

  2. Download the real files after cloning
    Terminal · Ubuntu / Debian
    git lfs pull

    Use this if you see small text pointer files instead of your big files.

  1. Install Git LFS
    PowerShell
    winget install GitHub.GitLFS

    Git for Windows already includes Git LFS if you ticked it in the installer, so you can skip this step. Check with git lfs version.

  2. Turn on Git LFS for your user
    PowerShell
    git lfs install

    You only do this once per computer.

  3. Tell Git LFS which files to handle
    PowerShell
    git lfs track "*.psd"

    Run this inside your project. It writes the pattern to a file called .gitattributes. Use quotes so your shell does not expand the pattern.

  4. Commit the tracking rule
    PowerShell
    git add .gitattributes && git commit -m "Track *.psd with Git LFS"
  5. Add and push big files as usual
    PowerShell
    git add . && git commit -m "Add big files" && git push

    Git stores a small pointer in the repo and uploads the real file to the LFS storage on your host. Files committed before you ran track stay in normal Git history.

Check it worked

  1. See which patterns Git LFS tracks
    PowerShell
    git lfs track
  2. List the files stored with Git LFS
    PowerShell
    git lfs ls-files
Undo it
  1. Stop tracking a pattern
    PowerShell
    git lfs untrack "*.psd"

    New files that match go back into normal Git. Commit .gitattributes afterwards. Files already pushed stay in LFS storage.

  2. Download the real files after cloning
    PowerShell
    git lfs pull

    Use this if you see small text pointer files instead of your big files.