How do I execute several git commands in a batch file without terminating after the first command?

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:

  1. invoke git in your batch files using the call command to run the git.cmd batch file and return back to yours:

    call git checkout %2
    call git fetch origin
    rem etc...
  2. invoke git in your batch file using the .exe extension explicitly to avoid the git.cmd batch file altogether. For this to work, you might need to make sure that you have your path and other environment variables set the way git.exe expects (that seems to be what git.cmd does in msysgit):

    git.exe checkout %2
    rem etc...