Is it possible to make a batch file for Git Bash?
So, I was wondering if there was a way to write a batch file that opens git bash inside the cm开发者_运维百科d window and called on certain git functions, pretty much like a macro. Is it possible to do this? I know that I can call "C:\Program Files (x86)\Git\bin\sh.exe --login -i" inside a cmd window to run git bash inside the window, and I've managed to do that with a batch file, but then it doesn't do anything until sh.exe's process ends.
Is this possible? How can I do this?
Note: I have found this: Reading Git commands using Batch(.BAT) file. The guy said this:
Hai All, Finally I got the solution for my question.By using below code ssippet, we can run the Git using BAT file
"c:\Program Files\Git\cmd\git.cmd" pull > c:\platform.txt"
vthe above code using from BAT file instead of using git pull or git push and any git command using GIT Bash. Thanks to all for posting your valuable comments and partial answer
But for me there is no git.cmd executable... and I would only use writing to a .txt file if a merge went wrong or something... however there is a git.exe executable in Git/bin. Apparently it Will let me do all the git functions, like add, push, commit, merge, etc. So I have two questions about it: Will I have to have the batch file change directories to the local repo and then call git.exe from there? Because it won't let me do git cd
. Also, say that I typed in git fetch upstream
inside a cmd window. If I type git merge upstream/master
, then will it remember what it had fetch previously?
Running git via git bash from a Windows batch file is almost certainly not what you really want to do. I assume you are talking about msysgit, and you appear to be trying to work around the lack of git.cmd file in your installation. If you're missing this file, then your installation is broken and I'd suggest you reinstall. You'll notice there is an option in the installer to put git in the PATH to run from cmd.exe, too.
Once you've fixed your installation, git will work more or less the same from cmd.exe as from bash, subject to a few caveats due to Windows and cmd.exe special characters. So yes, your fetch and merge example will work just fine.
If you want to operate on a git repository, you need to be inside the repository or set the GIT_DIR environment variable to the .git directory as needed.
Look at my answer here: Using msysGit from MinGW and vice versa
Might be applicable to you as well. Using the third or second option in the "Adjusting your path environment" will give you the git.cmd
and you can run that directly from cmd.
精彩评论