Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clone gitlab project that uses git lfs without giving password all the time

Tags:

gitlab

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 (!)..

  • ...

like image 252
TheCrafter Avatar asked Apr 02 '16 14:04

TheCrafter


People also ask

How do I get Git to stop asking for password?

You can avoid being prompted for your password by configuring Git to cache your credentials for you. Once you've configured credential caching, Git automatically uses your cached personal access token when you pull or push a repository using HTTPS.

How do I bypass the username and password in Git clone?

One way to clone a repository without having to enter your password would be to create an app-password and use it while cloning. That done, git won't prompt for user name and password. Mind that this is a URL and needs to be encoded as an URL then. This will leave the password in the git configuration.

How do I clone a Git repository LFS?

Once Git LFS is installed, you can clone a Git LFS repository as normal using git clone . At the end of the cloning process Git will check out the default branch (usually main ), and any Git LFS files needed to complete the checkout process will be automatically downloaded for you.

Why is Git asking for username and password every time?

If Git is always asking you for your username and password when pushing or pulling your code from a GitHub repository, This is a common problem if you use HTTPS clone URL for cloning the repository.


2 Answers

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.

like image 177
VonC Avatar answered Sep 28 '22 04:09

VonC


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.

like image 21
danf Avatar answered Sep 28 '22 02:09

danf