I’m not sure if this is true for all Windows git packages, but at least some use a git.cmd script as a wrapper around the actual git executables (for example git.exe). So when you’re batch file uses a git command, Windows is actually running another batch file.
Unfortunately, when one batch file invokes another, by default it ‘jumps’ to the invoked batch file, never to return (this is for compatibility with ancient MS-DOS command processors or something).
You can solve this problem in a couple ways:
-
invoke
gitin your batch files using thecallcommand to run thegit.cmdbatch file and return back to yours:call git checkout %2 call git fetch origin rem etc... -
invoke
gitin your batch file using the.exeextension explicitly to avoid thegit.cmdbatch file altogether. For this to work, you might need to make sure that you have your path and other environment variables set the waygit.exeexpects (that seems to be whatgit.cmddoes in msysgit):git.exe checkout %2 rem etc...