Git LFS is an extension for Git that replaces large files with text pointers in your Git repository, while storing the file content on a remote server.
This is a quick start guide on how to integrate Git LFS in your Git repository, using Artifactory as the LFS server.
- 'git' client installed (verify using $ git –version)
- Git LFS local repository in Artifactory
1. Download and install the Git LFS client. (verify using $ git lfs version)
2. Navigate to the root folder of a Git project you would like to set up LFS for. Alternatively, you can clone a project or create a new one. Verify it is has successfully connected to the Git repository.
($ git status)
3. In order to initiate Git LFS, run the following in the root directory of your project:
$ git lfs install
4. When using Git LFS, you have to specify which files you want to be tracked by the Git LFS client. You can specify specific files or by using wildcards. In this example, we will configure the Git LFS client to track all "*.zip" files in our project.
$ git lfs track "*.zip"
5. The above command has created a .gitattributes file in the project root directory. This file is crucial for the LFS client, and needs to be added and pushed to the remote Git provider:
$ git add .gitattributes
6. Add any *.zip file to the project directory (Note! Make sure the added file isn't an "empty" file as the LFS client will identify that and will not apply the LFS logic) and add them to the Git project:
$ git add test.zip
7. Commit the changes and added files:
$ git commit -m "testing Git LFS"
8. Prior to "pushing", we need to configure the Git LFS server (Artifactory).
Copy the content from the "Set Me Up" of the Git LFS repository in Artifactory to the .lfsconfig file in the root of your project. If the file doesn't exist, create it. This is how the file should look like:
url = "https://USER:PASSWORD@my.artifactory.com/artifactory/api/lfs/git-lfs-local"
(Important! The URL must NOT be localhost or 127.0.0.1)
9. Push the changes to your Git repository, LFS tracked files will be pushed to Artifactory.
$ git push origin master
By following the above steps, we ended up with credentials persisted locally in the .lfsconfig file.
Therefore you should proceed with caution and not push the .lfsconfig to your Git repository. Doing so exposes your Artifactory credentials to anyone who can view the project.
When the Git project is integrated with Git LFS and a new user clones the project, he will initially fail to get the LFS-tracked files. This is because he is missing the .lfsconfig file.
When not pushing the .lfsconfig to git, you should instruct users to configure this on their own with their own Artifactory account credentials.
Alternatively, you can configure the .lfsconfig without credentials and make it part of the Git repository.
Then, upon pushing or pulling, users will be prompted for credentials.
You can configure SSH authentication for Git LFS repositories in Artifactory.
1. Enable SSH Authentication in your Artifactory server and complete the configuration.
2. Upload your SSH Public Key in the SSH section of your user profile as described in Configuring User Authentication.
3. Make sure Artifactory is a "known host" on your system.
4. Change the URL in .lfsconfig as follows:
Good To Know
• Adding 'GIT_TRACE=1' to 'git' commands will verbose the output. Example usage:
$ GIT_TRACE=1 git push origin master
• After the first push, the [lfs] clause from .lfsconfig will be added to the .git/config file.
• $ git lfs help