git BASH: why is $HOME concatenation of path? - bash

Some context: trying to clone a repo with ssh url from git BASH, but getting the following error:
Could not create directory '/c/Usersusername/.ssh'
The authenticity of host '...' can't be established.
Why are the Users and username subdirectories getting concatenated? Is this expected? I'm assuming this is causing the error and the failed clone request.
From git BASH:
$ echo $HOME
/c/Usersusername
From Windows cmd:
C:\ echo %HOME%
C:/Users/username
I've tried $ setx home "C:/Users/username" .

Try and not set HOME: by default, git bash should use %USERPROFILE%
Try also to create in advance the .ssh folder, before using your SSH URL for cloning: that way, Git should directly go to the Host verification step, without failing on that folder creation.
Note: On Windows 10, with Git 2.32 for Windows, I do have a HOME set using C:\... backslash path, and it is correctly displayed as /c/... in a bash session without me setting it in .bashrc or .profile.

Related

What should i do to resolve this issue on Git?

I am new to Unix commands and would like to have some help regarding it.
I am want to practice commands on my Windows Machine. I have installed GitBash and I am trying to execute commands on it. But every time I press enter I get this issue:
$ git init
C:/Users/.git: Permission denied
lenovo#LAPTOP-7Q4QK8A7 MINGW64 /c/Users
$ git clone https://github.com/06-glitch/Rainbow/commit/32c6e7cc3c37d20ff368a2095c34522da297b174
fatal: could not create work tree dir '32c6e7cc3c37d20ff368a2095c34522da297b174': Permission denied
Could anyone please help me with this?
Problem:Your are trying to clone in the users folder which is not accessible.
Answer:Change your directory to the Desktop or any other folder and use the git commands
cd means "change directory"
Use the below code to change directory to root:
cd ~
or In my case my desktop name Aakarsh Teja so.. try cd to that name Remember you have to use quotes if your folder name consists of a SPACE.
cd "Aakarsh Teja"/Desktop
Now you can use your commands for git.
Make sure your git bash is in your destination folder.
Aakarsh Teja#MINGW64 ~/Desktop
$git clone <gitlink>

Git: rename directory (case-only) on Windows

I want to rename a directory versioned by Git on a Windows system (change the case of the directory name):
$ git mv docs DOCS
Rename from 'docs' to 'DOCS/docs' failed. Should I try again? (y/n) n
fatal: renaming 'docs' failed: Permission denied
I've also tried with the force-option - but with the same result:
$ git mv --force docs DOCS
Rename from 'docs' to 'DOCS/docs' failed. Should I try again? (y/n) n
fatal: renaming 'docs' failed: Permission denied
For some reason Git fails because it thinks DOCS already is an existing directory and the directory should be moved inside it. I know that I can rename & commit using a temporary directory name and then rename & amend-commit to the final name, but isn't there a way to tell Git that I don't want to move inside any other directory?
You can try to do it in 2 step.
$ git mv docs DOCS2
$ git mv DOCS2 DOCS
it will work
I have tried to rename my directory with TortoiseGit using rename, command prompt using git mv, and git bash using git mv. The move command was either mv Status status or git mv Status status2 and both of them respond "failed: Permission denied". So it seems I am either going to have to delete the git repository and create a new one with the new directory name structure or I am going to have to create a Linux VM, clone it down, and try to rename name it there. It seems only files can be renamed under windows, but directories just fail. As for people that say git mv works for them, there has to be something missing in your setup.
Since windows iד case sensitive you cant rename the file to the same letters. (Docs == docs [ignored case])
You can do it from git bash since git bash is cygwin and its case sensitive since its a unix emulator.
The command is git mv
git mv <old name> <new name>
Here is a demo from git bash. (windows 7)
No. There isn't a way to tell Git that you don't want to move the folder inside any other directory.
This is not a limitation of git, but rather a limitation of Windows and NTFS. Because the filesystem is case-insensitive, it reports that the case-changed new name already exists, which causes the behaviour that you encounter. Try a 2 step rename (with a temporary name), then commit, or changing it on a non-windows (technically on a case-sensitive filesytem) computer.

rsync (cwrsync) in Gitbash - The source and destination cannot both be remote. [windows 7]

I am trying to sync a local path to another drive using Git Bash in Windows 7. I downloaded cwRsync and copied the files over to my Git bash bin directory. I can run rsync but the following command gives me problems
rsync -av /c/00-dev/05-batch /f/RSYNC/
The source and destination cannot both be remote.
rsync error: syntax or usage error (code 1) at main.c(1135) [receiver=3.0.6]
Both the paths are correct but it won't sync.
Workaround: cd to /c and rsync using relative paths.
So this works:
cd /c
touch temp/test.txt
rsync temp/test.txt temp/test2.txt
while this doesn't, even if you cd to /c:
$ rsync /c/temp/test.txt /c/temp/test2.txt
The source and destination cannot both be remote.
Tested with the Git Bash that came with git 2.9.0.windows.1.
This works using cwRsync from Git Bash.
export MSYS_NO_PATHCONV=1
rsync -av /cygdrive/c/00-dev/05-batch /cygdrive/f/RSYNC/
cwRsync.exe needs /cygdrive/<drive-letter> for absolute pathing, so the simple rsync -av /cygdrive/c/00-dev/05-batch /cygdrive/f/RSYNC/ works from the cmd.
However, Git Bash converts paths like .../c/... to weird things like ...C:\.... The line: export MSYS_NO_PATHCONV=1 prevents that conversion. (See more: How to stop MinGW and MSYS from mangling path names given at the command line).
Use unset MSYS_NO_PATHCONV in the script to restore standard Git Bash behavior.
In Windows I tried cwRsync to sync data between folders located on Z:(network disk) and D:(usb stick) excluding a subfolder 'Data':
rsync -r -v --size-only --dry-run --exclude=Data --chmod=ugo=rwX /cygdrive/z/"Scan folder"/"Sub folder" /cygdrive/d/"Scan folder"/"Sub folder"
-r means recursively, -v verbose output, --dry-run is just for testing (data doesn't transfer), --exclude excludes subfolder or file(s), --chmod=ugo=rwX sets proper permissions (read more about permissions here with comments)
For cyrillic names on Windows use 'chcp 65001'.

'ssh-keygen' is not recognized as an internal or external command

I run git push -u origin master
It tells me that "Permission denied (public key) fatal: The remote end hung up unexpectedly"
Then I looked up on the internet and found that I had to generate an ssh key for my account on GitHub. However, upon doing so, when I tried to do ssh-keygen -t rsa "email#youremail.com" it simply said ssh-keygen is not recognized. I tried doing mkdir C:\ssh but that didn't work. If it helps I'm using Ruby Rails and I'm on a Windows computer. Could anyone help me?
2012:
ssh-keygen.exe is part of msysgit:
C:\path\to\msysgit1.7.11\bin\ssh-keygen.exe
if your %PATH% includes C:\path\to\msysgit1.7.11\bin\, you will have ssh-keygen.
Update 2015:
ssh-keygen.exe is part of Git For Windows, whose releases include PortableGit-2.4.3.1-2nd-release-candidate-64-bit.7z
c:\path\to\PortableGit-2.4.3.1-2nd-release-candidate-64-bit\usr\bin\ssh-keygen.exe
That means the %PATH% must include c:\path\to\PortableGit-2.4.3.1-2nd-release-candidate-64-bit\usr\bin (without the ssh-keygen.exe)
As I explained before, Git for Windows will soon phase out msysgit.
I detailed in "Why is it that if you download Git 2.0 from the net, you always get a 1.9.4 installer package?" how this new version is based on the more recent msys2 project.
I just had this issue and thought I'd share what I thought was an easier way around this.
Open git-bash and run the same command with the addition of -C since you're commenting in your email address: ssh-keygen -t rsa -C "email#youremail.com" command. That's it.
git-bash should have been installed when you installed git. If you can't find it you can check C:\Program Files\Git\Git Bash
The first time I did this it failed to create the .ssh folder for me so I had to open a standard Command Prompt and mkdir C:\Users\yourusername\.ssh
I followed below in windows (With Git for Windows installed)
Run "Git Gui" (Start --> Git --> Git Gui)
Click Help and then Show SSH Key
Click Generate Key if you do not have one already
Note:- this creates the key files under your personal profile folder C:\Users\YourUserID\.ssh\
No need to add anything to environmental variables! Just open up git bash and perform command the ssh-keygen in there.
Link to download git bash here
I found an easy solution to fix this :
In the command prompt, go to your git\bin directory,
and then execute your commands from here
If you have installed Git, and is installed at C:\Program Files, follow as below
Go to "C:\Program Files\Git"
Run git-bash.exe, this opens a new window
In the new bash window, run "ssh-keygen -t rsa -C""
It prompts for file in which to save key, dont input any value - just press enter
Same for passphrase (twice), just press enter
id_rsa and id_rsa.pub will be generated in your home folder under .ssh
Just go to heroku.bat and add:
#SET PATH="D:\Program Files (x86)\Git\bin";%PATH% after #SET PATH=%HEROKU_RUBY%;%PATH%
in my case it's in D:\Program Files (x86)\Git\bin, change it to the path you've installed Git to. (i just left it with my path so it will be clearer on how to write this)
I think you can add the location of the file ssh-keygen.exe in the PATH environment variable. Follow the steps: Go to My Computer->Right click->Properties->Advanced System Settings->Click Environmental Variables. Now click PATH and then click EDIT. In the variable value field, go to the end and append ';C:\path\to\msysgit1.7.11\bin\ssh-keygen.exe' (without quotes)
don't do anything just type in your command prompt
C:\> sh
then you got like this
sh-4.4$
# type here
ssh-4.4$ ssh-keygen -t rsa -b 4096 -C "example#example.com"
this should must work.
For windows you can add this:
SET PATH="C:\Program Files\Git\usr\bin";%PATH%
You probably should check this. Windows doesn't have that command built in.
I got it fixed by just adding ssh-keygen to my environment variables.
for those who does not choose BASH HERE option. type sh in cmd then they should have ssh-keygen.exe accessible
In my machine, ssh-keygen was available from powershell.

Git with SSH on Windows

I've went through the excellent guide provided by Tim Davis which is about configuring Git to work with SSH under Windows in order to produce a Git Server in order to have a main place for my DVCS.
I am in the process of creating a clone for my project. I’ve went through all the steps till this point, but I keep getting this from TortoiseGit:
git.exe clone -v “ssh://Administrator#127.0.0.1:22/SSH/Home/administrator/myapp.git” “E:\GitTest\myapp”
bash: Administrator#127.0.0.1: command not found
Initialized empty Git repository in E:/GitTest/myapp/.git/
fatal: The remote end hung up unexpectedly
Success
and nothing gets cloned.
BTW: The TortoisePLink comes up just before this message appears and asks me: “login as:” ( I thought that this info is given in the command, i.e: Administrator#blahblah.
My home variable is set to the correct place:
From a Git Bash shell:
echo $HOME
/c/SSH/home/Administrator
I’ve also tried using Putty’s plink instead of TortoisePLink (in both Git’s and TortoiseGit’s installation). This time the error was narrowed down to:
git.exe clone -v “ssh://Administrator#127.0.0.1:22/c:/SSH/Home/administrator/myapp.git” “E:\GitTest\myapp”
Initialized empty Git repository in E:/GitTest/myapp/.git/
fatal: The remote end hung up unexpectedly
I fought with this problem for a few hours before stumbling on the obvious answer. The problem I had was I was using different ssh implementations between when I generated my keys and when I used git.
I used ssh-keygen from the command prompt to generate my keys and but when I tried "git clone ssh://..." I got the same results as you, a prompt for the password and the message "fatal: The remote end hung up unexpectedly".
Determine which ssh windows is using by executing the Windows "where" command.
C:\where ssh
C:\Program Files (x86)\Git\bin\ssh.exe
The second line tells you which exact program will be executed.
Next you need to determine which ssh that git is using. Find this by:
C:\set GIT_SSH
GIT_SSH=C:\Program Files\TortoiseSVN\bin\TortoisePlink.exe
And now you see the problem.
To correct this simply execute:
C:\set GIT_SSH=C:\Program Files (x86)\Git\bin\ssh.exe
To check if changes are applied:
C:\set GIT_SSH
GIT_SSH=C:\Program Files (x86)\Git\bin\ssh.exe
Now git will be able to use the keys that you generated earlier.
This fix is so far only for the current window. To fix it completely you need to change your environment variable.
Open Windows explorer
Right-click Computer and select Properties
Click Advanced System Settings link on the left
Click the Environment Variables... button
In the system variables section select the GIT_SSH variable and press the Edit... button
Update the variable value.
Press OK to close all windows
Now any future command windows you open will have the correct settings.
Since this keeps coming up in search results for making git and github work with SSH on Windows (and because I didn't need anything from the guides above), I'm adding the following, simple solution.
(Microsoft says they are working on adding SSH to Visual Studio, and GitHub for Windows still doesn't support SSH...)
1. I installed "git for Windows" (which includes ssh and a bash shell)
https://git-scm.com/download/win
2. From the included bash shell (which, for me, was installed at: C:\Program Files\Git\git-bash.exe)
cd to the root level of where you want your repo saved (something like: C:\code\github\), and
Type:
eval $(ssh-agent -s) && ssh-add "C:\Users\YOURNAMEHERE\.ssh\github_rsa"
3. Type: (the SSH link from the repo)
git clone git#github.com:RepoName/Project.git
you are using a smart quote “ instead of " here:
git.exe clone -v “ssh://
^^^
Make sure you use the plain-old-double-quote.
I've found my ssh.exe in C:/Program Files/Git/usr/bin directory.
If Git for windows is installed, run Git Bash shell:
bash
You can run ssh from within Bash shell (Bash is aware of the path of ssh)
To know the exact path of ssh, run "where" command in Bash shell:
$ where ssh
you get:
c:\Program Files\Git\usr\bin\ssh.exe
I was trying to solve my issue with some of the answers above and for some reason it didn't work. I did switch to use the git extensions and this are the steps I did follow.
I went to Tools -> Settings -> SSH -> Other ssh client
Set this value to C:\Program Files\Git\usr\bin\ssh.exe
Apply
I guess that this steps are just the same explained above. The only difference is that I used the Git Extensions User Interface instead of the terminal. Hope this help.
When I typed where ssh it showed me multipe ssh.exe
user#pc MINGW64 /c/dev/
$ where ssh
C:\Users\user\AppData\Local\Programs\Git\usr\bin\ssh.exe
C:\Windows\System32\OpenSSH\ssh.exe
Deleting / moving these exe helped:
# copy from
# C:\Users\user\AppData\Local\Programs\Git\usr\bin
# to something like
# C:\Users\user\AppData\Local\Programs\Git\usr\bin\backup-ssh
ssh-agent.exe
ssh.exe
ssh-add.exe
This solved the issue for me.

Resources