问题
I am on windows-10. I want to create a batch-file to automate:
- Starting Git Bash in project folder
Running the following Git commands:
eval $(ssh-agent -s) ssh-add ~/.ssh/github_rsa git remote add origin git@github.com:git_user_name/git_repository_name.git
My current batch file below successfully starts Git Bash in the project folder, but I have not found anything which helps me learn how to run the git commands.
@echo off
cd /d C:\project_folder
start "" "%PROGRAMFILES%\Git\bin\sh.exe" --login -i <== edited per suggestion
回答1:
With direction from comment from bk2204 about "invoking sh.exe -c
" I found that the following worked.
I concatenated all 3 commands into one string and put this string after start "" "%PROGRAMFILES%\Git\bin\sh.exe" -c
and also added ; bash
to the end of the command string which keeps the Git bash command window open. I wanted window open so I could continue to use it eg by entering manually git add ., git commit, push origin master, etc
start "" "%PROGRAMFILES%\Git\bin\sh.exe" -c "eval $(ssh-agent -s) &&
ssh-add ~/.ssh/github_rsa &&
git remote add origin git@github.com:git_user_name/git_repository_name.git; bash"
来源:https://stackoverflow.com/questions/61735998/windows-batch-file-start-git-bash-and-run-git-commands