Git push over SSH by CMD file on Win 8 - windows

I need to create a .cmd file that pushes my repository to remote. However, .cmd files are open in standard command line and if I run "git push" in it, I guess standard HTTP authentication is used - I'm not asked for passphrase for my ssh key file and the authentication of course fails.
Pushing works fine in Git shell (Powershell configured for git from "Github for Windows"), however, how can I create clickable shortcut in Windows which runs a command in this shell?
I tried
C:\Users\Richard\AppData\Local\GitHub\GitHub.appref-ms --open-shell "push.cmd"
which did not work.
Also, I tried to run the .cmd file in normal shell adding
#setlocal
#set PLINK_PROTOCOL=ssh
git push
as advised here:
Running a batch file in git shell
but it made no difference - no query for my ssh key, authentication fails.
Can you help me make one of the two solutions working? Thanks.

Related

How to deploy my website with one click using Git Bash on windows and a scripted command

I have a html/css/js website which is stored in GitHub and developed on my Windows 10 machine using Visual Studio 2019.
Currently I'm deploying it using the Git Bash console and then running a git ftp command to push any deltas to the server.
Specifically:
I have pinned shortcut on the task bar which opens Git Bash in the root directory of the website.
Once the console has opened, I execute the following command to push to the server: "git ftp -v -u "frankray" push"
A two click deployment is no big deal, but I'd really like to do this in one click from the task bar (as a prelude to automating the CI).
Problem: I cannot for the life of me workout how to pass in the git ftp command into the console and run it, say from a batch file or perhaps directly calling git-bash.exe with the command passed in as a parameter.
I can't imagine it's hard to do, but I haven't worked out what I've been doing wrong. Please help.
Posting my comment as an answer
Unfortunately there isn't a list of command line options for git-bash. This superuser question may provide some more info.
A possible solution (verified by OP) is passing the -c parameter (command to be executed) to the target like so;
"C:\Program Files\Git\git-bash.exe" --cd="C:\Users\frank\Documents\Professional\Contracting\5. Frank Ray & Associates Ltd\Website\frankray.net" -c 'git ftp -v -u "frankray" push ; read -p "Press any key to continue"'

svn hangs on checkout in Windows

Attempting to check out a repository using svn checkout svn+ssh://USER#REPO .
I have set my %SVN_SSH% variable to include the -v flag when calling plink.exe, and the last log I get is Using username "USER". After that the command line hangs indefinitely.
I get similar problems attempting to checkout the repository using TortoiseSVN and the Subversion integration in Intellij.
I have no problems connecting to the server using PuTTY or calling plink directly in the command line. Using the -v flag with plink, I get prompted for my password immediately after the line where it hangs using svn checkout.
I have Windows 7 Ultimate SP 1, svn version 1.8.13, plink release 0.60.
The problem seems to be that you have to use public key authentication for SVN to be able to use SSH in Windows properly.
There are a few tutorials online for how to do this, but the one that worked for me was this one.
The important difference, which I didn't find in other tutorials, was the usage of the chmod command to change access permissions to the public key file on the server.
It might be too late to say, but i've had the similar problem.
In mine case the issue was in the command line of the plink.exe.
To properly fix all issues and do not type infinite logins and passwords:
Use pageant.exe to add the ppk key and avoid manual input of the password.
Use SVN_SSH environment variable with the -l "<username>" parameters to avoid manual input of the user name and avoid usage the username in the svn repository url.
Use SVN_SSH environment variable with the -batch parameter to avoid hangs in a script mode.
The resulting SVN_SSH environment variable should look like this:
SVN_SSH="<path-to-plink>/plink.exe" -batch -l "<USER>"
warning: backslash character in a path in the SVN_SSH variable is an escape character, you have to use a double to self escape it or replace it a forward slash - /.
But be careful with the git svn command, because the SVN_SSH variable can break the git with the message:
Can't create session: Unable to connect to a repository at URL 'svn+ssh://...': Error in child process: exec of '' failed: No such file or directory at .../Git/mingw64/share/perl5/Git/SVN.pm line 310.
In that case you have to use the ssh-pageant from the msys or cygwin tools instead.
I've create another post with detailed description on how to do that step by step both for the svn.exe and git.exe: How to use git-svn with svn+ssh url

Windows scheduled task to git push to github

I hope to add a Windows Scheduled Task to git push to github every night. I have a CMD file. When I run the CMD file on the windows command prompt, it works fine. But when I run it via windows scheduled task. It's stuck forever. The status is "running". And from the log I can see it successfully started the git bash shell. Any idea?
echo git push > i:\gitpush
echo 'pushing' >>log1
C:\WINDOWS\SysWOW64\cmd.exe /c ""C:\Program Files (x86)\Git\bin\sh.exe" --login i:\gitpush" >>log1 2>>error
echo 'done pushing' >>log1
del i:\gitpush
Here is the log output:
'pushing'
Welcome to Git (version 1.7.4-preview20110204)
Run 'git help git' to display the help index.
Run 'git help <command>' to display help for specific commands.
Then I did an experiment to rename gitpush script to a wrong file name. And it exited immediately with the error "No such file or directory", which is expected. It shows the gitpush script is passing in correctly to the bash but for some reason it's stuck.
The reason I have to go through git bash shell is because I don't know how to setup public key in windows command line shell without using git bash shell.
Thanks!
I don't know how to setup public key in windows command line shell
Public/private keys work also in a DOS shell, provided you define the %HOME% environment variable (referencing the parent directory of the .ssh)
The trick with Windows Scheduled Task is to make sure:
who is actually running the task (the "system account"? or the actual user?)
Displaying "env" can help debugging the issue.
where it is run: if git push depends on the current path to properly push the current repo, you need to be certain that your task runs where it is supposed to.

windows batch file exits when running mercurial commands

For daily backup of my mercurial repositories on Windows XP I used a simple batch file hg_backup.bat which just did some directory changes and mercurial calls with a pause command in the end like this:
#Z:
#cd \hg_backup\drawings
hg pull -v
#cd \hg_backup\src\scripts
hg pull -v
#cd \hg_backup\eagle4\lbr
hg pull -v
#pause
This worked fine with mercurial up to 1.7 (installed with TortoiseHg). However since mercurial 1.8 it starts the very first mercurial command and then exits abruptly without reaching the following commands or even the end of the script. The command window just disappears.
I had the same problem some time before, when I tried the same thing with git, but didn't investigate further, because I use git for one repository only. It seems to me, there's some return code of the hg command line call involved which causes the script to end instead of executing the other command but I couldn't verify this yet.
Has anyone an idea why this happens or maybe even how to fix it?
If your hg is a hg.bat or hg.cmd, use call hg and see if it starts working.
The command.com shell executes batch files replacing the old script (to save memory), and requires using call to start a batch script and continue execution later. This behavior remains in Windows cmd.exe for compatibility.
I had the exact same problem, but the solution provided by #grawity didn't work for me (and I have no idea why).
The solution in my case was to replace call with cmd /C, like so:
cmd /C hg sum
cmd /C hg stat

new computer, git pull origin is asking for a password

on my new computer, I setup git and my putty.exe and ssh key etc. just fine.
So I do a:
git pull origin
and then at the command prompt, I am asking for a password.
I have no idea what password it wants, and then it also asks for my server's password after a few failed attempts at the first password.
it asks for:
blahblah#serveradmin.com password:
What is going on?
(my git rep is hosted on a shared unix isp)
I already setup pageant to use my private key, and it gave me a popup to enter my passphrase. This is how it works on my old computer, and then when I open git-bash and do a 'git pull origin' it works fine without asking me anything.
Update II
So let me summarize what is happending here:
I have the exact same setup at my office computer (windows7) (desktop), and it works fine w/o asking me any questions. All I do b4 using git is run a .bat file that loads up pageant.exe:
C:\putty\pageant.exe "E:\code\pg_pk.ppk"
Then doing a git pull origin works fine, doesn't ask me for any password.
I had this on my laptop also, and it worked just like my office computer UNTIL I installed windows 7 on it. Now it asks me for a password even though pageant.exe is running (I can see it in my taskbar, and the key is loaded).
So today I grabbed the .bat file and the entire /putty folder and put it on my laptop, still doesn't work, it is asking me for a password when I type: git pull origin
(I am running the same version of git on both computers)
Really confused, what could it be?
It isn't clear from your question whether or not you set up Git to actually use PuTTY. What is the content of your GIT_SSH environment variable?
It should be set to the full path to plink.exe. Even better yet: if you also use TortoiseSVN or TortoiseHg, set GIT_SSH to their TortoisePlink.exe. TortoisePlink has been modified to not read from the standard input, but instead pop up a dialog window, if something goes wrong. Git redirects standard input, so that you cannot actually type anything into plink, if, for example, your server's IP address changes and plink asks you to type yes to confirm it, that won't work. (You'll have to invoke plink or putty manually, then say yes and they will save it in the registry.) TortoisePlink will instead pop up a Yes/No dialog box.
You ssh key passphrase.
To remedy, you can recreate a key on your new machine using ssh-keygen and then save in the git origin
I'd double-check your SSH keys--looks like it's not properly sending your identity.
I have found that pageant sometimes just does not work. IMHO it is far easier to set it up using a blank password key with command line ssh client. From memory:
Generate public/private key using git bash:
ssh-keygen -t RSA -C email#address
DO NOT specify password.
Upload the the contents of %USERPROFILE%.ssh\id_rsa.pub
Git should just work, including windows command line, git bash, tortoise, git extensions etc.
I encountered this problem as well. What worked for me, oddly enough, was not creating the repository via TortoiseGit, but rather via git init.

Resources