Batch files with git commands

4,874 views
Skip to first unread message

Roman Terekhov

unread,
Apr 7, 2008, 8:41:28 AM4/7/08
to msy...@googlegroups.com
Hi

I like to write windows batch files with the git commands, that I want to execute together.
But with the msysgit only the first command is executed while the the others are skipped.
Any ideas why this happen?

This works great with cygwin git.

--
Roman Terekhov

piy...@gmail.com

unread,
Apr 7, 2008, 9:30:37 AM4/7/08
to Roman Terekhov, msy...@googlegroups.com
Hello:

On Apr 7, 9:41 pm, "Roman Terekhov" <roman.terek...@gmail.com> wrote:
> I like to write windows batch files with the git commands, that I want to
> execute together.
> But with the msysgit only the first command is executed while the the others
> are skipped.
> Any ideas why this happen?

I don't really understand why this happens, but I have a work around.

Try prefixing the desired git command with the cmd.exe command "call".

Example:

@rem This script checks out multiple repositories under a path.
@rem This is before I discovered git submodule. ;-)
@rem Obvious variable decls omitted.
set reps=my-git-repo-1 my-git-repo-2

for %%i in (%reps%) do (
if exist %%i (
cd %%i
echo ^>^>^>^> Updating %%i
call git.cmd pull -v
cd ..
) else (
echo ^>^>^>^> Checking out %%i
call git.cmd clone http://%user%@%host%/%parent_path%/%%i.git/
)
)

End Example

This worked for me under Git-preview20080301. There is a more recent
contribution on the origin/mob branch [1] that says "Exit
%errorlevel%", which might affect this behavior. I have not checked
it yet.

[1] b3f99268c117a7e8d369025d20e8ef3cdc70c0a0

Best regards,
Clifford Caoile

Peter Harris

unread,
Apr 7, 2008, 10:57:44 AM4/7/08
to piy...@gmail.com, Roman Terekhov, msy...@googlegroups.com
On Mon, Apr 7, 2008 at 9:30 AM, <piy...@gmail.com> wrote:

>
> On Apr 7, 9:41 pm, "Roman Terekhov" wrote:
> > I like to write windows batch files with the git commands, that I want to
> > execute together.
> > But with the msysgit only the first command is executed while the the others
> > are skipped.
> > Any ideas why this happen?
>
> I don't really understand why this happens, but I have a work around.

Back in the days of DOS, the command interpreter could only run one
script at a time. When you run git (which the system finds as
"git.cmd") from inside a batch file, the contents of git.cmd replace
the currently executing script.

For compatibility reasons, when they added the ability to run multiple
scripts, they made you use "call". This braindamage persists in
Microsoft systems to this day.

> Try prefixing the desired git command with the cmd.exe command "call".

This isn't a workaround so much as a documented "feature" of the
Windows command shell.

You don't have problems in cygwin because cygwin uses bash instead of
the default Windows command interpreter.

Peter Harris

Reply all
Reply to author
Forward
0 new messages