Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.

like image 996
IcyFlame Avatar asked May 23 '13 08:05

IcyFlame


People also ask

How do I auto upload to GitHub?

One potential way to automatically upload files to GitHub is to include "git" commands within the scripts generating the output files to automate the process of committing and pushing these files to your git repository.


2 Answers

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.

like image 141
IcyFlame Avatar answered Sep 29 '22 14:09

IcyFlame


Commiting your work once a day as a big chunk is not an effective use of version control. It's far better to make small, regular, atomic commits that reflect steps in the development of the code base (or whatever else is being tracked in the repository)

Using a shell script is perhaps overkill - most people use aliases to automate git commands, either as shell aliases or git aliases.

In my case I use shell aliases - a couple of which are:

alias gp='git push' alias gc='git commit' alias gca='git commit -a' alias gcm='git commit -m' alias gcam='git commit -am' 

so for me to do what you're asking would be:

gcam "My commit message";gp 

This isn't a lot of typing and is hardly boring, I do this and similar git operations literally dozens of times a day (I know - because I check my shell history).

The reason for using small aliases rather than a script is so that I have the flexibility to use different ways of committing, If I used a script I would lose that flexibility.

like image 36
Abizern Avatar answered Sep 29 '22 14:09

Abizern