Loading...

How to upload large files to a git repository?

question devtips git
Ram Patra Published on September 22, 2024

By default, you cannot upload files larger than ~100MB (for most Git hosting service providers). If you do so, the git push command will fail with an error. The recommended way to work with large files is to use Git LFS.

To enable Git LFS (Large File Storage) in a Git repository, follow these steps:

1. Install Git LFS

If Git LFS isn’t installed yet, you need to install it:

  • macOS (via Homebrew):
    brew install git-lfs
    
  • Ubuntu (via APT):
    sudo apt install git-lfs
    
  • Windows: You can download and install Git LFS from the official site: Git LFS.

2. Initialize Git LFS

After installation, initialize Git LFS in your local Git environment:

git lfs install

This step needs to be done only once for your local machine.

3. Track Specific File Types

Specify which files Git LFS should track by running the following command. For example, to track .psd files:

git lfs track "*.psd"

You can track other file types like large images, videos, or binaries in a similar way. This creates or updates a .gitattributes file in your repository with the tracked file extensions.

4. Add and Commit

After tracking the files, stage and commit the .gitattributes file that was modified:

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

5. Push Files to Repository

From now on, when you add and commit files that match the tracked patterns, Git LFS will handle those files. Use normal Git commands to push changes:

git add <files>
git commit -m "Add large files"
git push

6. Verify LFS File Tracking

You can check what files are being tracked by Git LFS with:

git lfs ls-files

Once enabled, Git LFS will automatically manage large files according to the patterns you specified. Now, your git push command should execute with no issues.

But do keep in mind that there are file size limits even with LFS enabled, depending on which Git hosting service you use. Below are the general file size limits and quotas for common Git hosting platforms:

1. GitHub

  • Individual File Size Limit: GitHub enforces a 2 GB limit per file, even when using Git LFS.
  • Storage Quota: By default, a repository gets 1 GB of free LFS storage. If you exceed this, you’ll need to purchase additional storage, with increments of 50 GB for a fee.
  • Bandwidth Quota: GitHub provides 1 GB/month of free bandwidth for LFS file downloads. Additional bandwidth usage can be purchased.

2. GitLab

  • Individual File Size Limit: GitLab doesn’t enforce a hard file size limit for LFS, but it strongly recommends keeping files below 10 GB for performance reasons.
  • Storage Quota: For GitLab.com free users, each project has a 10 GB limit on total storage (including Git LFS). For paid plans, this quota can be increased.

3. Bitbucket

  • Individual File Size Limit: Bitbucket has a soft limit of 2 GB per file, though it’s recommended to keep files under 1 GB.
  • Storage Quota: Bitbucket provides 1 GB of free LFS storage for free accounts. For additional storage, you need to upgrade to a paid plan.
  • Bandwidth Quota: Bitbucket free accounts have a bandwidth quota of 1 GB/month for Git LFS, with higher limits for paid plans.

Key Points:

  • Exceeding the size limits for files or quotas typically results in errors when pushing to the repository.
  • To push larger files or extend storage/bandwidth, you might need to upgrade to a paid plan with more LFS storage and bandwidth.

Make sure to review the hosting service’s terms to manage LFS storage effectively.

Presentify

Take your presentation to the next level.

FaceScreen

Put your face and name on your screen.

ToDoBar

Your to-dos on your menu bar.

Ram Patra Published on September 22, 2024
Image placeholder

Keep reading

If this article was helpful, others might be too

question chromium devtips August 27, 2020 How to take screenshots of the entire webpage without any extensions?

I always used an extension like Awesome Screenshot in Chrome to take screenshots of any website. However, you do not need an extension to capture a screenshot of a webpage.