-3

i would like to make a "script" to perform some commands for me in git bash. i would then start git bash and type git myScriptName and hit enter, the it would perform:

    cd myProjectFolderName (ENTER)
    git init (ENTER)
    git add -A (ENTER)
    git commit -m 'letMeWriteSomeThingHereAndIHitEnterAndItEndsCommentWith' (ENTER)
    git push myRemoteName myBranch (ENTER)

and then do nothing, i would also like to do the same with:

    cd myProjectFolderName (ENTER)
    git init (ENTER)
    git pull myRemoteName myBranch (ENTER)

and then do nothing.

Thanks a bunch for any help regarding this, a plus would be if someone even went ahead and made the script :) Thanks

user1344948
  • 141
  • 1
  • 3
  • 11

1 Answers1

2

You could start with this:

gitCommands.sh:

function go_on {
  echo -ne "$1 [Y, n]\r"
  read answer
  if [ "$answer" = "n" ]; then
    echo "exit"
    exit 0
  fi
}

function call {
  go_on "$1"
  $1
  echo ""
}

call "cd myProjectFolderName"

echo "Type commit message"
read commit_message
call "git commit -m $commit_message"

The function call executes the function 'go_on'. This echos the string parameter (for example cd myProjectFolderName [Y, n]) on the commandline, after that it waits for your input. If you type Y or simply press enter, the script goes on (with executing this command). If you type "n", the script stops.

user1251007
  • 15,891
  • 14
  • 50
  • 76
  • looks awfully complicated :/ could you maybe tell me what the different parts do so i can apply them like i described? :) please – user1344948 Apr 23 '12 at 13:04
  • @user1344948 - I added some comments and corrected little mistakes. You can now apply this example directly, just save 'gitCommands.sh' on your computer, make it executable and run it. You can add further things as you described by your own. If you have problems, just ask! – user1251007 Apr 23 '12 at 13:59
  • @user1344948 - If you find my answer helpful, you should upvote it. If you think, this is the right answer, you should accept the answer. – user1251007 Apr 25 '12 at 21:13