How to cd into the local git repo from an AppleScript

applescriptcommand linegitterminal

I am running a Mac using OSX Yosemite v10.10.5.

I want to push my local git repo to my remote using AppleScript.

So the git code would be:

shell

git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/myusername/my-project.git
git push -u origin master

But in order to run this from the terminal, first I need to cd into my local directory.

cd my-directory

So how would I do all this from an AppleScript? Or the JavaScript option in the Script Editor would also help.

Best Answer

Basically you can use

do shell script "cd my-directory && git init"
do shell script "cd my-directory && git add README.md"
...