简体   繁体   中英

How do I clone a repository that includes Git LFS files?

On my Ubuntu system, I installed Git LFS as well as Git, and cloned a repo that has some of its files managed by Git LFS. But those files didn't download, other than a marker file. (I didn't realize they weren't the whole file until I checked the file size, because they displayed in my file system with the right names, in the right places.)

I see from this answer that git lfs clone has been deprecated, and simply git clone should work. But when I tried that I got confused. I am used to just running git clone https://foobar.git and letting it set up the directory. But Git LFS won't work unless it has been initialized with git lfs install in each directory where it is being used. (That's why this didn't work the first time, at least now I know that.)

So I set up the directory, ran git init and git lfs install inside it, and then ran git clone https://foobar.git . Which will create a directory for the repo nested inside the directory I created, will it not? That seems wrong somehow.

It is going to take a few hours to clone this repo, so I would like to be confident I'm doing this right. Looking at the documentation on GitHub , it seems to say the above set of commands is correct - if you read the whole thing. The bits of information are separated by a thousand words or so. Is that the way to do it?

git lfs install does two things: it sets up hooks in your local repository, and it adjusts your global (ie, user-specific) configuration to contain the filter commands necessary for Git LFS to work properly.

If you're not in a repository yet, you probably want to run git lfs install --skip-repo and let it install the filter commands into your ~/.gitconfig . If you manage this file yourself, copy the lines that it adds into the one that you manage. Then, move into a non-Git-controlled directory and run git lfs env and make sure that the last few lines look like this:

git config filter.lfs.process = "git-lfs filter-process"
git config filter.lfs.smudge = "git-lfs smudge -- %f"
git config filter.lfs.clean = "git-lfs clean -- %f"

That will show you that your configuration is set up properly. Once you have that set up, simply clone the repository, and assuming it's set up with the proper entries in its .gitattributes file, Git will automatically pull down the Git LFS files necessary, and when Git LFS is invoked, it will install the necessary hooks.

On Debian, the Git LFS package installs the filter commands by default, so it probably does the same on Ubuntu. You can check for the entries in /etc/gitconfig , and if they're present, you won't need to do anything at all; things should just work, and git lfs env will automatically show you the right thing without any setup.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM