0

I am using mac osx, and would like to make a simple bash script for uploading changed files to my github repository.

It should ask for my comments to the files that i'm committing something like:

git add .
git commit -m 'prompt for comments'
git push origin master

I don't know how to make the script, i just want to do it via terminal with a single command.

any help would be much appreciated.

I do know how to make aliases in my .bash_profiles though :-)

Thanks.

2
  • Start with help read and google "bash user input" Commented Dec 26, 2013 at 21:28
  • 1
    Leave the -m option off commit, and git commit itself will simply open your preferred editor to enter the commit message. No need to prompt and read it separately. Commented Dec 26, 2013 at 23:00

2 Answers 2

6

You may try:

#!/bin/bash  
git add .  
read -p "Commit description: " desc  
git commit -m "$desc"
git push origin master
Sign up to request clarification or add additional context in comments.

Comments

2

Here's a super simple solution that's more generic than bash (more portable):

#!/bin/sh
printf "Commit msg: "
read msg
git commit -am "$msg"
git push origin master

It doesn't do git add to add new files but -a adds tracked files to be staged for commit. This is often what one wants. If you really want to do git add . just add that line and remove the a from options to git commit.

1 Comment

It doesn't work. I get this: '{~} -> gitup Commit msg: change fatal: Not a git repository (or any of the parent directories): .git fatal: Not a git repository (or any of the parent directories): .git'

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.