Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git commit and push via batch file on Windows

I do same task often of committing and pushing changes to remote branch. Being lazy sometimes, I needed to put set of git commands to automatically perform these steps:

cd D:\wamp\www\projectName
git checkout dev
git add .
git commit -am "made changes"
git push
pause

I also tried:

cd D:\wamp\www\projectName
call git checkout dev
call git add .
call git commit -am "made changes"
call git push
pause

and

cd D:\wamp\www\projectName
git.exe checkout dev
git.exe add .
git.exe commit -am "made changes"
git.exe push
pause

Everything works excpet for the final push command. Here is output:

D:\wamp\www\givingcircle>git checkout dev
Already on 'dev'
Your branch is ahead of 'origin/dev' by 1 commit.

D:\wamp\www\givingcircle>git add .

D:\wamp\www\givingcircle>git commit -am "made changes"
# On branch dev
# Your branch is ahead of 'origin/dev' by 1 commit.
#
nothing to commit, working directory clean

D:\wamp\www\givingcircle>git push
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

D:\wamp\www\givingcircle>pause
Press any key to continue . . .

As you can see, for push, I am getting:

D:\wamp\www\givingcircle>git push
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

When I run above commands via git shell itself, everything works fine. I have also added git to Windows Path env variables.

Does anyone have an idea of why it works on git shell and not on batch command ? (even though other commands work but not push)

like image 554
Dev01 Avatar asked Dec 05 '13 10:12

Dev01


People also ask

How do I run a batch file in Windows?

Run a batch file from the Command Prompt To run a batch file, move to the directory containing the file and type the name of the batch file. For example, if the batch file is named "hope. bat," you'd type "hope" to execute the batch file.


1 Answers

For me, by default, Windows executes .sh files correctly using Git Bash. So I would write your script as a regular bash shell script:

#!/bin/sh
cd /d/wamp/www/projectName
git checkout dev
git add .
git commit -am "made changes"
git push
echo Press Enter...
read
like image 140
janos Avatar answered Sep 19 '22 14:09

janos