Windows scheduled task to git push to github - windows

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.

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"'

Get Git Shell to run command after starting

You can do
start powershell -command ls
to open PowerShell and get it to list files. I'm trying to do a similar thing with Git Shell. Currently I have
%LOCALAPPDATA\GitHub\Github.appref-ms --open-shell -command ls
which opens Git Shell, but doesn't do anything else. Is it possible to run a command after starting Git Shell in this way?
Since this hasn't been answered I'm going to offer an alternative solution of using git-bash instead of the MS application reference file.
start /b cmd /c "C:/Program Files/Git/git-bash.exe" /C/path/to/script.sh
See this question: Cant run shell script using Git Bash interface on Windows10

Git push over SSH by CMD file on Win 8

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.

SVN update by executing TortoiseProc.exe in a script created in bash

I need to run a SVN update in script create in bash but it fails. Can please you help to find out what am I doing wrong?
Script:
echo SVN Update
alias svn="cd C/Program Files/TortoiseSVN/bin"
START TortoiseProc.exe /command:update /path:"cd C/CCUE" /closeonend:0
Error in output:
+echo SVN $'Update\r'
SVN Update
' alias 'svn=cd C/Program Files/TortoiseSVN/bin
+ START TortoiseProc.exe /command:update '/path:cd C/CCUE' $'/closeonend:0\r' - line 7: START: command not found
Defining an alias for a directory change is not the same as executing that directory change. Also changing directory is not a good idea since then TortoiseProc would not know what directory you want to update.
I'd recommend using TortoiseProc.exe full path or putting TortoiseSVN/bin in PATH.
The error could be caused also by bash not finding START.EXE.
I was able to invoke by hand TortosieProc without START using the following line
$ "/c/Program Files/TortoiseSVN/bin/TortoiseProc.exe" /command:update /path:"d:\Dir\LocalRepo" /closeonend:0 &
Notice how the path parameter has to be invoked by TortoiseProc and therefore has to follow Windows syntax. TortoiseProc complained if I used a UNIX style for the path.
Tested on cygwin, Windows 7, TortoiseSVN 1.7

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

Resources