Git LFS

Git LFS (Large File Storage) is an extension to Git that allows for the versioning of large files by replacing them with text pointers while storing the actual file content on a separate server. This helps keep repositories manageable in size and improves performance. We'll explore various ways to use the git lfs command, providing you with a comprehensive guide to enhance your Git workflow.

1. Installing Git LFS:

Before using Git LFS, ensure it is installed on your system. You can install it using:

bash
git lfs install

This initializes Git LFS in your local repository.

2. Tracking Files with Git LFS:

To start tracking large files with Git LFS, you can use:

bash
git lfs track "<file-pattern>"

Replace <file-pattern> with the pattern of files you want to track. This command creates or updates the .gitattributes file to indicate that the specified files should be handled by Git LFS.

3. Listing Tracked Files:

To view a list of files being tracked by Git LFS, you can use:

bash
git lfs ls-files

This command shows the paths of files tracked by Git LFS.

4. Removing Git LFS Tracking:

If you want to stop tracking a file with Git LFS, you can use:

bash
git lfs untrack "<file-pattern>"

Replace <file-pattern> with the pattern of files you want to stop tracking.

5. Migrating Existing Files to Git LFS:

To migrate existing files to Git LFS, you can use:

bash
git lfs migrate import --everything --include="<file-pattern>"

Replace <file-pattern> with the pattern of files you want to migrate. This command converts existing large files in your repository to Git LFS.

6. Uploading Files to Git LFS:

To manually upload a file to Git LFS, you can use:

bash
git lfs push --all origin master

Replace origin and master with your remote and branch names. This command pushes all Git LFS-tracked files to the Git LFS server.

7. Downloading Files from Git LFS:

To manually download Git LFS-tracked files, you can use:

bash
git lfs pull

This command fetches and downloads Git LFS-tracked files from the Git LFS server.

8. Viewing Git LFS Configuration:

To view the Git LFS configuration for a repository, you can use:

bash
git lfs env

This command displays the current Git LFS configuration, including the LFS server URL.

9. Changing Git LFS Server URL:

If you need to change the Git LFS server URL, you can use:

bash
git lfs env url <new-url>

Replace <new-url> with the URL of your desired Git LFS server.

10. Locking and Unlocking Files:

Git LFS allows you to lock and unlock files to control write access. To lock a file, you can use:

bash
git lfs lock <file-path>

To unlock a file, you can use:

bash
git lfs unlock <file-path>
11. Viewing Lock Status:

To view the lock status of files, you can use:

bash
git lfs locks

This command shows the status of locked files, including who locked them and when.

12. Pruning Old Files:

To remove old versions of files stored in Git LFS, you can use:

bash
git lfs prune

This command removes unreferenced objects and reduces the size of the Git LFS store.