1

I am on . I want to create a to automate:

  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
    

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 commands.

@echo off
cd /d C:\project_folder
start "" "%PROGRAMFILES%\Git\bin\sh.exe" --login -i <== edited per suggestion
3
  • 2
    You want to invoke sh.exe -c "commands here". Don't use --login or -i unless you're planning on typing the commands manually. Commented May 11, 2020 at 17:56
  • BTW, "%ProgramFiles%\Git\bin\sh.exe" would be more succinct, and no less robust. Commented May 11, 2020 at 18:01
  • so the next line in my batch file would be sh.exe -c "eval $(ssh-agent -s)" . I did want to have those three commands run and then have git bash open so i could continue to use it manually eg git add . etc Commented May 11, 2020 at 18:10

1 Answer 1

4

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 [email protected]:git_user_name/git_repository_name.git; bash" 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.