I tried to put a series of GIT commands that I always use continuously togeter as batch files so that I don’t repeat myself too much. For example, I have this batch file called update_repo_branch.bat to update a local repo and synch a branch with the remote branch:
@echo off
if(%1) == () goto end
if(%2) == () goto end
cd %1
git checkout %2
git fetch origin
git merge oring/%2
:end
Good to be lazy, but what I found is that when a GIT command is finished, it seems to send an exit flag back to terminate whatever is running. Therefore, using a batch file to exectute them all in one go simply doesn’t work. Any idea how to work around it?
I’m not sure if this is true for all Windows git packages, but at least some use a
git.cmdscript as a wrapper around the actual git executables (for examplegit.exe). So when you’re batch file uses agitcommand, 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: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):