Skip to content

Git LFS doesn't work with npm install #899

Closed

Description

@animeoakes

When I run npm install --save git+ssh://[email protected]:bmahsman/bubblegum.git, npm checks out the text files that git lfs puts in place of the actual assets. It appears npm isn't using my local user account's ~/.gitconfig, i.e. the filters aren't being used and git-lfs is not being executed.

The issue could be with npm, but I wonder if git lfs install only sets up git lfs for the current user, while npm install is using some kind of global settings for all users. I detail the issue more in this question, which no one has answered after a month. Any help is appreciated.

Activity

  1. animeoakes commented on Dec 17, 2015

    @animeoakes
    Author

    I made an issue on npm as well. npm/npm#10857

  2. technoweenie commented on Dec 20, 2015

    @technoweenie
    Contributor

    Git LFS doesn't understand the git+ssh protocol. You can use [email protected]:bmahsman/bubblegum.git instead.

  3. animeoakes commented on Jan 14, 2016

    @animeoakes
    Author

    After poring over the output from git and npm with export GIT_TRACE=1 and npm config loglevel verbose, I believe I have figured out how to get this to work, at least with GitLab (I have since moved from GitHub to GitLab, which also supports Git LFS).

    Step 1. Inside of your repository, run the following command (replace bubblegum with the name of your repo) and then commit the resulting .gitconfig and push:

    $ git config -f .gitconfig lfs.url https://gitlab.com/brynn.mahsman/bubblegum.git/info/lfs
    

    Step 2. In the directory in which you want to npm install your project, run for example:

    $ npm install -S https://gitlab.com/brynn.mahsman/bubblegum.git
    

    note: For this to work with GitHub, it would appear that the lfs.url to use is: https://api.github.com/lfs/<user or organization>/<repository name>, e.g.

    $ git config -f .gitconfig lfs.url https://api.github.com/lfs/brynn.mahsman/bubblegum
    

    The .gitconfig you commit to the repository allows the git commands used by npm install to know what lfs.url to use. I'm not sure if this solution only masks the fact that npm install can't figure out the lfs.url without you explicitly specifying it in .gitconfig. In other words, when I run the command git clone https://gitlab.com/brynn.mahsman/bubblegum.git, git somehow knows the lfs.url even if I don't have the .gitconfig in the repository. Would someone please enlighten me as to whether this is something npm install should be able to do without having to write this .gitconfig?


    edit: This solution apparently disables batch mode when retrieving files from GitLab.

  4. technoweenie commented on Jan 14, 2016

    @technoweenie
    Contributor

    note: For this to work with GitHub, it would appear that the lfs.url to use is: https://api.github.com/lfs//, e.g.

    If your git host supports LFS properly, the LFS endpoint should always be your git remote with a "/info/lfs" suffix. You should only have to configure lfs.url if your LFS service is hosted separately from your Git service.

    GitHub's lfs-authenticate command over SSH does return that "api.github.com" url, but https://github.com/brynn.mahsman/bubblegum.git/info/lfs works just fine too.

    You can run git lfs env to see what url it will attempt to use.

    $ git lfs env
    git-lfs/1.1.0 (GitHub; darwin amd64; go 1.5.1; git fbbfd7d)
    git version 2.5.4 (Apple Git-61)
    
    Endpoint=https://github.com/github/git-lfs.git/info/lfs (auth=none)
    Endpoint (dev)=http://github.dev/technoweenie/whatever.git/info/lfs (auth=none)
    
  5. animeoakes commented on Jan 14, 2016

    @animeoakes
    Author

    Thanks for helping me out with this. Knowing that <url>/info/lfs is standard simplifies things a lot.

    Do you have any idea why npm install does not have the proper lfs.url on its own without having to tell it explicitly with a .gitconfig in the repository?

    I noticed that when you give npm install a repository it first makes a bare clone with --mirror in its cache directory, and then attempts to make a non-bare clone from that, which then is the basis for the files it installs to node_modules/bubblegum/.

    Is there something about creating a bare mirror on the local filesystem that makes it lose the ability for your Git host to report the correct lfs.url?

  6. technoweenie commented on Jan 14, 2016

    @technoweenie
    Contributor

    Git LFS replaces pointers on checkout to the working directory. I don't think bare clones will do anything LFS related. If npm wants to support LFS, they'd have to download the actual objects manually. Git LFS doesn't really have any convenient commands for it, but they could be added if npm wanted to add support.

  7. animeoakes commented on Jan 14, 2016

    @animeoakes
    Author

    Thanks. In that case, I believe this is now entirely in npm's court. I'll make an issue in their project and see if they want to support it. The .gitconfig workaround should suffice for now.

  8. technoweenie commented on Jan 14, 2016

    @technoweenie
    Contributor

    I noticed that when you give npm install a repository it first makes a bare clone with --mirror in its cache directory, and then attempts to make a non-bare clone from that, which then is the basis for the files it installs to node_modules/bubblegum/.

    Ok, I think I get what's happening, and why you need the .gitconfig:

    The first repo is a clone from a remote git host. But since it's a bare clone, LFS is not invoked at all. The second repo is a clone of the bare repo. Its origin remote is some local file path, and not a remote git host. That's why you need the .gitconfig.

    Perhaps the client could detect this, and look at the config of the repo's local origin to get the original remote git host?

  9. feugy commented on Oct 6, 2016

    @feugy

    Hi there.

    Although this problem is on npm side, I post here a workaround for other users

    We got the same problem here, but workaround provided by zxcpoiu didn't work due to authentication (we're using a private repo).

    After some research on Git Enterprise Doc, we found that providing a .lfsconfig file on the repo that has lfs items solved the issue:

    [remote "origin"]
        lfsurl = ssh://[email protected]/user/repo.git
    
  10. pjho commented on Nov 8, 2016

    @pjho

    @feugy champion! Cheers for that.

    For anyone else on bitbucket I needed to drop the ssh:// to get that working so:

    [remote "origin"]
        lfsurl = [email protected]:org-name/repo-name.git
    
  11. vincentvent commented on Aug 26, 2019

    @vincentvent

    I could not get this to work on github. Trying to npm install a private repo and I get:

    Error downloading object: ************************ : batch request: ssh: Could not resolve hostname c: Name or service not known: exit status 255

    I added the .gitconfig URL and ran npm install https://githubrepo

    Everything clones well except for the LFS file.

  12. bk2204 commented on Aug 26, 2019

    @bk2204
    Member

    From seeing this message, it sounds like you're trying to use a local Windows path to clone, which won't work. If you're using the latest master, you can instead specify a file URL (not a local path), like this: file:///c%3a/Some/Path/Component/Here. This feature isn't in 2.8.0, but it should be in 2.9.0 when that's released.

  13. vincentvent commented on Aug 26, 2019

    @vincentvent

    Thank you @bk2204 I am using a URL
    npm install https://githubrepo

    It does have [lfs]
    	url = https://github.com/medicalinformaticscorp/repo.git/info/lfs
    

    In the .gitconfig

  14. bk2204 commented on Aug 26, 2019

    @bk2204
    Member

    Could you please open a new issue for this, then, including the information requested in the CONTRIBUTING file? This sounds like a different issue than this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions