Windows批处理文件-启动git bash并运行git命令 [英] Windows batch file - start git bash and run git commands

查看:1011
本文介绍了Windows批处理文件-启动git bash并运行git命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在自动化:

I am on windows-10. I want to create a batch-file to automate:

  1. 在项目文件夹中启动Git Bash
  2. 运行以下Git命令:

  1. Starting Git Bash in project folder
  2. 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

我下面的当前批处理文件成功启动了项目文件夹中的Git Bash,但是我没有找到任何东西可以帮助我学习如何运行命令.

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

推荐答案

在bk2204关于调用sh.exe -c"的注释的指导下,我发现以下方法可行.

With direction from comment from bk2204 about "invoking sh.exe -c" I found that the following worked.

我将所有3条命令串联为一个字符串,并将此字符串放在start "" "%PROGRAMFILES%\Git\bin\sh.exe" -c之后,并且还在命令字符串的末尾添加了; bash,这使Git bash命令窗口保持打开状态.我希望打开窗口,以便可以继续使用它,例如通过手动输入git add ., git commit, push origin master, etc

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" 

这篇关于Windows批处理文件-启动git bash并运行git命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆