Automatic git Commit and Push

At times you would like to save some time or find it little boring to repeat same process of committing and pushing to remote git branch; in that case you can find below tip useful. Here is a tip that would help you commit your project changes and push to remote branch with a single click.

Create a file push.sh (notice the .sh extension for bash file) and put following contents in it:

#!/bin/sh
###########################
cd D:/wamp/www/yourProjectFolder
# switch to branch you want to use
git checkout master
# add all added/modified files
git add .
# commit changes
git commit -am "made changes"
# push to git remote repository
git push
###########################
echo Press Enter...
read

Now put that file under your project folder. When you run it, your changes will automatically be committed and pushed to remote branch. Change the commands accordingly to reflect your branch or commit message. Here is the screenshot of what I get after running above commands:

pic

If you would like to customize the commit message, you would modify the script a bit:

#!/bin/sh
###########################
cd D:/wamp/www/yourProjectFolder
# switch to branch you want to use
git checkout master
# add all added/modified files
git add .
# commit changes
read commitMessage
git commit -am "$commitMessage"
# push to git remote repository
git push
###########################
echo Press Enter...
read

And of course, you can add any git commands you would like to automate to that file.

Please notice it is just a tip for those who didn’t know they can automate git commands that way. However, this isn’t usually a good practice; it is always a good idea to review your changes and then commit and push instead of pushing automatically like that. This just turns out to be handy when you are in hurry (or lazy) and are sure about what you are doing.

Please make sure to add PATH environment variable in case script doesn’t work for you.

About these ads

2 thoughts on “Automatic git Commit and Push

  1. Pingback: https://confluence.atlassian.com/plugins/servlet/mobile#content/view/278071958 | MyRailsWay

  2. Pingback: Git Cheat Sheet | MyRailsWay

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s