Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
825 views
in Technique[技术] by (71.8m points)

how to automate the "commit-and-push" process? (git)

I have a git repo. And after each major change, that I make in the codebase, what I do is that I go to the terminal and execute a set of commands.

git add .
git commit -m 'some message'
git push origin master

These are the same each day and the process is quite boring. Can anyone suggest a way to somehow automate this process?

I am running a Linux Mint 14 OS.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can very easily automate this using Bash scripting.

git add .

echo 'Enter the commit message:'
read commitMessage

git commit -m "$commitMessage"

echo 'Enter the name of the branch:'
read branch

git push origin $branch

read

store the above code as a .sh file(say gitpush.sh)

And since you have to make this sh file an executable you need to run the following command in the terminal once:

chmod +x gitpush.sh

And now run this .sh file.

Each time you run it, It will ask you for the commit message and the name of the branch. In case the branch does not exist or the push destination is not defined then git will generate an error. TO read this error, I have added the last read statement. If there are no errors, then git generates the pushed successfully type-of message.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...