20

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)

4
  • It probably can't find the ssh agent. Try reading the SSH_AUTH_SOCK environment variable from the git shell and defining that variable in the Windows shell. Commented Dec 5, 2013 at 10:45
  • @Barend: Thanks but how do I read and define it ? Commented Dec 5, 2013 at 10:57
  • In bash: echo $SSH_AUTH_SOCK. In cmd: set SSH_AUTH_SOCK=<value> (where <value> is whatever port number the echo command returned). Commented Dec 5, 2013 at 11:38
  • I ran this at cmd and then ran bat file but still the same result: set SSH_AUTH_SOCK=/tmp/ssh-AxHhVr4004/agent.4004 and also ran set SSH_AUTH_SOCK=4004 Commented Dec 5, 2013 at 11:50

3 Answers 3

33

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
Sign up to request clarification or add additional context in comments.

1 Comment

how to run this ?
2

I had a similar need, to be able to move code from BBCloud to our development test servers, for stage 1 testing.

To do this, I created a Windows scheduled task:

Under "Actions", I added "C:\Program Files\Git\bin\bash.exe" in Program/script field (the quotes were required).

In the "Add arguments" field, I entered c:\path\to\bash script\pull.sh.

I then completed the Task Scheduler wizard (run frequency, time, etc.).

I then created a bash script, using Nano in Git Bash for Windows containing:

#!/bin/bash
cd /c/path/to/bash script
git pull

I would prefer a push to the repository automatically pushing down to the test server, but Pipes, Webhooks, and DeployHQ don't seem to be a solution for our environment.

Comments

0

Try this one !!

cd c://TESTS/path
set HOME=%USERPROFILE%
GIT COMMAND GOES HERE
pause

1 Comment

Any rationale behind this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.