Why do Git commands fail via Win32-OpenSSH on Windows 10? - windows

I have set up Win32-OpenSSH on a Windows 10 system, and I am using Git for Windows 2.16.1.
I have created a bare test repository, from which I can clone just fine via the file URL:
git clone file:///c:/test.git
Cloning into 'test'...
remote: Counting objects: 33, done.
remote: Compressing objects: 100% (32/32), done.
remote: Total 33 (delta 11), reused 0 (delta 0)
Receiving objects: 100% (33/33), done.
Resolving deltas: 100% (11/11), done.
SSHD is also running fine, I can open a shell from my tablet, and access the repository directory via SFTP:
> sftp oli#localhost
oli#localhost's password:
Connected to oli#localhost.
sftp> pwd
Remote working directory: /C:/Users/Oli
sftp> cd /c:/test.git
sftp> pwd
Remote working directory: /c:/test.git
sftp> ls
HEAD config description hooks info objects packed-refs refs
sftp> bye
But cloning via SSH fails for some reason:
> git clone ssh://oli#localhost:22/c:/test.git
Cloning into 'test'...
oli#localhost's password:
fatal: ''/c:/test.git'' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
User "Oli" definitely has the correct access rights, and we have seen above that the repository exists and is a valid Git repository. I also tried many different syntax variants on the path.
I have read every Q/A here on Git/SSH/Windows, and the Git Pro book, and the Git reference, and the OpenSSH manuals, and the Win32-OpenSSH wiki.
What am I missing?

This has been answered by Konstantin in this question (Thanks for the link, Aurel):
The problem is - cmd.exe doesn't understand single-quoted parameters.
Git passes the path to the repository enclosed in single quotes, which does not work in cmd.exe.
This can actually be seen in the Git error message above, if you look close enough:
fatal: ''/c:/test.git'' does not appear to be a git repository
So I have set up the workaround that Konstantin suggested:
create shell scripts gup.sh and grp.sh in my home directory on the server, each containing the single line git-upload-pack.exe $* resp. git-receive-pack.exe $*
use parameter -u 'sh gup.sh' in the initial clone operation (when doing this in cmd.exe, use double quotes...)
configuring the cloned repository with commands git config remote.origin.uploadpack 'sh gup.sh'and git config remote.origin.receivepack 'sh grp.sh'
...and it works.
Sadly, Konstantin's answer is not the accepted one, and the least upvoted one. So if this helps you, too, upvote his answer!

Related

git push in WSL2 environment hang up during Writing Objects step

Symptoms
I have a git workspace in WSL2 environment. The workspace is located under /mnt/c/workspace/repo where is also visible from Windows by the path C:\workspace\repo.
When I do git push from WSL2 side in the workspace, Git hang up with this message.
Enumerating objects: 39, done.
Counting objects: 100% (39/39), done.
Delta compression using up to 16 threads
Compressing objects: 100% (24/24), done.
Writing objects: 34% (9/26)
This is the other observed behavior and environment information in this context.
I can push these files from Windows side with git for windows without any problems.
I can push several times just after cloning files. It won't work after some of my push operations.
This repository just contains text files. The entire repository size is less than 1MB
I've used this environment for several months but I observed this issue just only for this repository
This problem also happened when I copied entire folder to ~/workspace/repo where is not exposed to Windows directly.
The remote is configured to connect with SSH and use the key under /home/<username>/.ssh
Environment information
Linux image in WSL: 20.04.2 LTS (Focal Fossa)
Git version: 2.25.1
Windows version: Microsoft Windows [Version 10.0.19042.844]
$ git config --global --list
user.email=<my mail address>
user.name=<my name>
http.postbuffer=524288000
Tried workarounds
Configureing http.postBuffer
git config --global http.postBuffer 524288000
I've followed this answer in different question in stackoverflow.
https://stackoverflow.com/a/26663047/3200358
This workaround won't work for me.
Windows permission change attrib -r +s
I've followed this workaround to fix some permission problem in Windows side.
https://stackoverflow.com/a/63483040/3200358
attrib -r +s C:\workspace\repo
This workaround won't work for me.
Tried sudo git push
I've tried sudo git push for in case when git command can't access some lock files.
sudo GIT_SSH_COMMAND='ssh -i /home/<username>/.ssh/id_rsa' git push origin master
This workaround won't work for me.
Using https to push
The error message was changed. But this workaround won't work for me.
$ git push --set-upstream origin master -vvvv
Pushing to https://github.com/kyasbal-1994/<repo-name>.git
Enumerating objects: 39, done.
Counting objects: 100% (39/39), done.
Delta compression using up to 16 threads
Compressing objects: 100% (24/24), done.
Writing objects: 100% (26/26), 5.53 MiB | 7.42 MiB/s, done.
Total 26 (delta 6), reused 0 (delta 0)
POST git-receive-pack (5802813 bytes)
error: RPC failed; curl 92 HTTP/2 stream 0 was not closed cleanly: CANCEL (err 8)
fatal: the remote end hung up unexpectedly
fatal: the remote end hung up unexpectedly
Everything up-to-date
Have you tried invoking Windows' git from WSL by using the path to the Windows git.exe? In fact you could set up an alias in your .bashrc:
alias wgit='/mnt/c/path\ to\ git/Git/git.exe`
This way, you have a Windows executable dealing with Windows files instead of a Linux executable dealing with Windows files, though I'm a little fuzzy on how things work with the mounting.
However, I'm not sure how user-friendly this may be when entering paths.
Assuming that works, there's probably even a way to write a smart wrapper function in bash that detects which file system the repo is on and invokes the right git executable...
As an alternative, you may have more luck maintaining 2 separate repos (WSL & Windows) and then syncing via push/pulls from a server.

Jenkins pipeline Git error: “Host Key Verification Failed” when connecting to remote repository

I am using my PC as a server to build my Jenkins script with declarative pipeline.
when running a git clone on the git bash, it works well:
$ git clone ssh://guillaumed#myserver.com:29418/myProjects/thisProject.git ThisFirmware
Cloning into 'ThisFirmware'...
remote: Counting objects: 889, done
remote: Finding sources: 100% (203/203)
Receiving objects: 79% (121769/152721), 48.11 MiB | 10.35 MiB/s
but running it on the same machine through pipelining :
sh "git clone ssh://guillaumed#myserver.com:29418/myProjects/thisProject.git ThisFirmware"
gives me the following error
[Pipeline] sh
+ git clone ssh://guillaumed#myserver.com:29418/myProjects/thisProject.git ThisFirmware
Cloning into 'ThisFirmware'...
Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
any hints?
To be sure I was using the same key, thanks to Jens, the pipeline script couldn't find the key.
Doing cat ~/.ssh/id_rsa.pub on the pipeline, resulted in + cat /c/windows/system32/config/systemprofile/.ssh/id_rsa.pub
cat: /c/windows/system32/config/systemprofile/.ssh/id_rsa.pub: No such file or directory
So I copied the ssh file from my guillaumed user ssh path to the SYSTEM ssh path but I can't use it if i'm logged in with SYSTEM user instead of guillaumed user.
what do I have to do?
this link didn't help.
Indeed, you can't checkout with ssh if you are logged as SYSTEM.
To checkout as "thisUser":
You'll need to configure your Jenkins.
1/ add a user "thisUser"
2/ add user's ssh credentials "thisUser-ssh-credentials"
3/ use ssh-agent plugin https://wiki.jenkins.io/display/JENKINS/SSH+Agent+Plugin
Then configure your pipeline
dir(server_workspace)
{
sshagent(credentials: ['thisUser-ssh-credentials'] )
{
sh "git clone ssh://thisUser#domain.com:port/yourProjects/thisProject.git"
}
}

Git remote push: failed to load advapi32.dll

I am new to Git and Github; and I came across a problem. There is a similiar question here (git bash failed to load advapi32.dll), but they are experiencing a different problem and there are no answers either. I have searched online and was unable to fix this. Here is the issue:
I am using Git Bash to push/pull commits to Github. When I try to push my work, I get this error saying "failed to load advapi32.dll ". I do have this file in my registry. The full Git message is bellow. It is worth noting here, that despite this error, Git is uploading and downloading commits perfectly fine; I just want to fix this problem in case it causes more issues in the future.
$ git push origin master
failed to load advapi32.dll
Counting objects: 3, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 418 bytes | 418.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To https://github.com/khash021/reflections.git
98a7bd9..b982ba4 master -> master
Thanks,
Khash
This problem occurs because the credential halper has been set to wincred and you do not have wincred installed. To verify this, run the command
git config --global credential.helper
if the result says "wincred", this is your problem. To unset the credential helper, run the command:
git config --global --unset credential.helper
That should solve the problem.
First, check your Git version: if it was v2.16.1.windows.2, from 4 days ago, it was quite buggy.
Try with the one released today: v2.16.1.windows.3: uncompress PortableGit-2.16.1.3-64-bit.7z.exe anywhere you want, and define a simplified PATH for testing.
well you could adding the flag:
$ git push origin master --all
Also, given that the .dll file is a system file, check that git has the permission to access it.

Using a network drive as git repository

So, I've created a git repository on the networked drive:
git init --bare --shared
and that works fine. Then, I clone it to a local drive with
git clone z:/testgit
and that also works fine. Then I add a file, stage, and commit
git stage *
git commit -m "test commit"
and that ALSO works fine. BUT! When I try to push to the origin, I get this error.
git push origin
Counting objects: 3, done.
Writing objects: 100% (3/3), 225 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: error: unable to write sha1 filename ./objects/f3/e6e90a7465421306fae05c18153260973542e3: Permission denied
remote: fatal: failed to write object
error: unpack failed: unpack-objects abnormal exit
To z:/testgit14
! [remote rejected] master -> master (unpacker error)
error: failed to push some refs to 'z:/testgit'
When attempting to use git stage * directly on the server (on a non --bare git project) I get similar errors.
I have full access to the drive in file explorer, and even able to initialize the repository with git. SSH shouldn't even apply here since it's not a server, it's a networked drive. Everything I've read about git says that this should work. I've read dozens of "how to's" that all say these exact steps, but no one complaining about permission denied, UNLESS they're talking about SSH public keys missing on servers (which, as I've said, shouldn't apply).
What permissions am I missing? Where should I look for and set the proper permissions?
What happens when you try to create the file that git is complaining about?
echo test > ./objects/f3/e6e90a7465421306fae05c18153260973542e3
It's possible that git is creating a new folder (f3) and the folder is not getting the correct permissions, either due to ACL inheritance misconfiguration or because the local machine is trying to adjust the permissions on newly created folders and getting it wrong.
If it were Linux, it could be because the network drive was connected with the wrong mount options, or the umask was set incorrectly, but I'm not sure whether those are available to be changed on a Windows machine.

github who am I? (OSX)

I think I'm github USER_A, but github thinks I'm USER_B. First, I check who I am:
$ git config --list
color.ui=auto
push.default=simple
user.name=USER_A
user.email=USER_A#gmail.com
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
core.ignorecase=true
core.precomposeunicode=true
remote.origin.url=https://github.com/USER_A/MY_REPO.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
Then, I git clone my repo:
$ git clone https://github.com/USER_A/MY_REPO.git
Cloning into 'MY_REPO'...
remote: Counting objects: 9, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 9 (delta 0), reused 0 (delta 0), pack-reused 6
Unpacking objects: 100% (9/9), done.
Checking connectivity... done.
Then I change something, commit, and push:
$ git push
remote: Permission to USER_A/MY_REPO.git denied to USER_B.
fatal: unable to access 'https://github.com/USER_A/MY_REPO.git/': The requested URL returned error: 403
This the only thing Github says about this error.
Why does git/github think I'm pushing as USER_B?!
EDIT: based on comments, I ran this test:
$ ssh -T git#github.com
The authenticity of host 'github.com (192.30.252.131)' can't be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,192.30.252.131' (RSA) to the list of
known hosts.
Hi **USER_A**! You've successfully authenticated, but GitHub does not provide
shell access.
I don't have a ~/.ssh/config or /etc/ssh/ssh_config file. I'm on a Mac FWIW.
I found the problem, my Mac keychain had USER_B. I found it when I searched for "github" in the Keychain app. I've updated the question to reflect this is a Mac-specific problem/solution.
I had the same problem. I was able to find out what key has been used by git using following command:
ssh -v -T git#github.com
Then, I saw another key is being used by github; So, I added my default key to SSH Agent:
ssh-add ~/.ssh/id_rsa
Then, problem solved :-)
Here are a couple things I would do if your having trouble:
Run
Vics-iMac:ansible vic$ git config --list
Explanation: When you configure git typically for the first time there are a lot of things that are done during the setup phase. One of them is configuring who you are, and what email address you use. If you examine the following output from the command above. You will see the user.name being used.
user.name = BlahBlah Name
user.email = blahadklhf#gmail.com

Resources