bash并运行git命令

bash并运行git命令

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

问题描述

我在 windows-10 .我想创建一个 batch-file 自动化:

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 [email protected]:git_user_name/git_repository_name.git

我下面的当前批处理文件成功启动了项目文件夹中的Git Bash,但是我没有找到任何东西可以帮助我学习如何运行 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

推荐答案

在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 [email protected]:git_user_name/git_repository_name.git; bash"

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

08-13 03:46