Clone gitlab project that uses git lfs without giv

2019-02-17 18:09发布

问题:

I decided to try git lfs on gitlab. I noticed that it doesn't work with ssh so I decided to use https for it. Push works just fine but when I tried to clone my project it asked me for a username and a password for every file.

That's kind of annoying. Is there any workaround to it?


EDIT 2018

This problem persist, where the real solution? There are a simple and direct recipe for it?

The links https://git-scm.com/docs/gitcredentials and git-lfs/wiki/Tutorial have perhaps something, but no objective solution.

Situation described by my git lfs env,

git-lfs/2.4.0 (GitHub; linux amd64; go 1.8.3)
git version 2.7.4

LocalWorkingDir=
LocalGitDir=
LocalGitStorageDir=
LocalMediaDir=lfs/objects
LocalReferenceDir=
TempDir=lfs/tmp
ConcurrentTransfers=3
TusTransfers=false
BasicTransfersOnly=false
SkipDownloadErrors=false
FetchRecentAlways=false
FetchRecentRefsDays=7
FetchRecentCommitsDays=0
FetchRecentRefsIncludeRemotes=true
PruneOffsetDays=3
PruneVerifyRemoteAlways=false
PruneRemoteName=origin
LfsStorageDir=lfs
AccessDownload=none
AccessUpload=none
DownloadTransfers=basic
UploadTransfers=basic
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"

and when I do git clone https://github.com/myPrivate/project1 the problem clonning process is not complete (bug), and was giving usernae and password all the time...

Problems also when try to do credentials (see issue #2223, etc.)


Trying report:

  • git config credential.helper outputs nothing, empty message.

  • git config -f .lfsconfig lfs.url https://github.com/myPrivate/MyProj1 accepts anything... So, is the browser URL or .git URL?
    After it the command git add .lfsconfig say "fatal: Not a git repository (or any of the parent directories): .git" in both cases (URL with or without .git)

  • git config credential.https://github.com/myPrivate/MyProj1 myusername say "fatal: not in a git directory", but of course, I need to clone first (!)..

  • ...

回答1:

As mentioned in git-lfs issue 993:

Because the LFS server and the git server can be separate endpoints, it is possible that a user has permission for the git server but not the LFS server.

In this case, if there is a credential manager installed, the credentials will not be reset, and LFS will use them on each subsequent request without ever invalidating them.

You should check your git config credential.helper output.
On Windows, it should be (with recent 2017-2018 Git releases) "manager".
Open the Windows Credential Manager and clear out or fix any GitHub credential entry.

Note: issue 2349 points out that Git-LFS had a problem to ask for credentials (in absence of an helper), because of a lack of pty/tty, but that has likely been fixed.


Transtating to dummies

(consolidating the answer and the comments)

  1. check git --version, if less tham 2.16, install better as instructions here using PPA

  2. check your git config credential.helper output, if it is empty,
    execute this line: git config --global credential.helper /usr/share/doc/git/contrib/credential/libsecret/git-credential-libsecret
    ... Them check again your git config credential.helper output: need to be this /usr/... path.

  3. Cloning...

    3.1. (as commented) Do first: git ls-remote https://github.com/myPrivate/MyProj1... That should prompt for your GitHub username and password account. Repeat that command to check that the second times, it does not prompt you for anything.

    3.2. Do your usual git clone (with care remove the broken old with sudo rm -r oldBrokenBadClone)... Giving username-and-password once.

Final notes about tests in many UBUNTU LTS servers... Sometimes, when you cloned before this procedure you can't fix the problem (git pull erros like "git-credential-libsecret: not found"). The solution is to remove all old cloned repo (caution with rm -rf). Seemingly you can do git config --global credential.helper any time, so, do it. Clone again — perhaps giving username-and-password twice but will be fine after it.



回答2:

You can use Git's credential helper which git lfs supports (has a permanent store and in-memory cache options).

I also noticed git lfs had some issues related to this which have been resolved.



回答3:

If no password is required to actually access the files and you're accessing with an https://server.com/path/to/repo URL then it should work (as of git-lfs 0.5.3). One possibility is that your configuration has lfs.batch = false. Try git -c lfs.batch=true clone https://server.com/path/to/repo --- no credential helper required.