How to make Git-LFS work and configure it with Artifactory in 5 min

From version 3.9, Artifactory supports Git Large File Storage (LFS) repositories on top of Artifactory's existing support for advanced artifact management.

 Artifactory support for Git LFS provides you with a fully functional LFS server that works with the Git LFS client.

In addition, from version 4.4, Artifactory supports authenticating your Git LFS client via SSH.

Prerequisites:

  • 'git' is properly installed (run $ git --version to verify).

  • Git LFS local repository in your Artifactory.

Step-by-step guide

  1. Download the Git LFS client from: https://git-lfs.github.com/.

    At the time of writing this article, the current version of Artifactory (v5.2) does not support SSH authentication for Git LFS client versions 2.x. To check if your version of Artifactory supports SSH authentication for Git LFS v2.x, please refer to this JIRA issue.
    If you are unsure, we recommend using Git LFS version <= 1.5.6.

  2. Verify that Git LFS is properly installed by running $ git lfs version.

    Git LFS must be initialized by running $ git lfs install (see step 5 below), similarly to $ git init.

     

  3. Start a new project or clone a git project, that is already connected to a git host and is up-to-date with your host. For example, you may clone any of your projects on github.

    To make sure your branch is up-to-date run $ git status. If everything is configured correctly, you should get the following messages:

    $ On branch master$ Nothing to commit, working tree clean$ Your branch is up-to-date with 'origin/master'.

  4. In your git directory, run $ git lfs install to initialize Git LFS in your project.

  5. In Git LFS you have to track the files you wish to push using the Git LFS client. You can either track specific files, or select patterns using wildcards. In this example we will track all '*.zip' files.

    Therefore either copy a zip file into your git directory, or create a new file. (Note: Make sure your file isn't empty, as the client is checksum based and doesn't support working with empty files).

  6. Run $ git lfs track "*.zip"

    This creates a '.gitattributes' file.

  7. Add the zip and .gitattributes files:

    $ git add .gitattributes

    $ git add test.zip

  8. Commit the files added: $ git commit -m "test gitlfs"
    Tip: If you want the Git LFS client to automatically fetch artifacts from a configured LFS server, you should also modify the .lfsconfig file (explained below) which will be added and committed along with the other files. This will prevent other users from configuring their own .lfsconfig file as it will be cloned along with the Git repository.

  9. Before "pushing", you need to configure a Git LFS host to obtain the LFS files.
    In your Git directory, open your .lfsconfig file or create a new one.
    Enter the "Set Me Up" popup for your Git LFS repository in Artifactory and copy the [lfs] clause into the .lfsconfig file.

    (NOTE: The Artifactory URL specified in your .lfsconfig file must NOT be localhost or 127.0.0.1.)

  10.  $ git push origin master

    Your tracked file should be in your Git LFS repository.

    You will be prompted to enter your credentials when pushing. Alternatively, you can provide basic authentication credentials in your .lfsconfig file.

    url = "http://<user>:<password>@<artiServer>/artifactory/api/lfs/<GitLFSrepoKey>"



Footnote:

It is also possible to use Git LFS with Gerrit.

Here is a blog that elaborates on this and how to set it up together with Artifactory:

http://blogs.collab.net/git/scm/gerrit-productivity-hack-handling-large-binary-files-with-gerrit-artifactory-and-git-lfs#.WOtSQlN95hE

You can migrate from using GitLFS on GitHub to a local GitLFS repository on Artifactory.

 

Extra Troubleshooting

  • Use $ git status to show your current status.

  • Adding GIT_TRACE=1 to a push command will enable verbose output. For example,
    $ GIT_TRACE=1 git push origin master

  • After the first push, the [lfs] clause from the .lfsconfig file should be added to the .git/config file (in the git directory). For example,

[core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true ignorecase = true precomposeunicode = true[remote "origin"] url = https://github.com/MYGITHUB/PROJECT.git fetch = +refs/heads/*:refs/remotes/origin/*[branch "master"] remote = origin merge = refs/heads/master[lfs "http://my.artifactory:8081/artifactory/api/lfs/lfs-local"] access = basic

Configuring Git LFS Authentication with SSH

 

Make sure you have your SSH authentication configured properly, and that Artifactory has been added as a known host on your system.

To authenticate with SSH, change the lfs URL in both the .lfsconfig and .git/config files as follows:

ssh://$USERNAME@$HOST:$PORT/artifactory/<repoKey>

 

For example:

url = "ssh://admin@my.artifactory.com:1339/artifactory/lfs-local"