Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
May 1, 2020 10:18 am GMT

Automating git push with just a single bashcommand

Wouldn't it be great if we could make whole git process automated instead of typing everytime same git commands to push file on to github repository.

We can do a simple hack to automate the whole process with just one bash command. Yes! you heard it right. One bash command can push entire repository from you local machine to github.

So lets start by writing a simple bash script and save it on your home directory with git-push.sh

echo "Enter your message"read messagegit add .git commit -m"${message}"if [ n "$(git status - porcelain)" ];then echo "IT IS CLEAN"else git status echo "Pushing data to remote server!!!" git push -u origin masterfi

Tl;DR. Basically this is a self explanatory code. Basically it is taking all the file file from your folder and pushing it to the github.
If condition checks it the files are already push or not. If it would have been already pushed then it will just return else it will push the files to the github repository.

Now, we will make this file an executable file by changing the permission using chmod command.

chmod +x git-push.sh

or

chmod 755 git-push.sh

Once the script is executable we will need to copy it to a directory that in our system expects to contain executable scripts and code. On most systems we will have a choice between two directories. If we are the only user of our system you can copy our script to either /usr/bin or /usr/local/bin. If you share your system with other people it's best to copy your script to /usr/local/bin. You will most likely need super-user privileges to copy our script to either of these directories so most likely we need to use the sudo command.

sudo cp git-push.sh /usr/bin/git-push.shsudo cp git-push.sh /usr/local/bin

This will make our script accessible globally so that we can use it from anywhere and anytime we want.

Alt Text

Moreover, if you want to make push scheduled over particular time you can use crontab job scheduler to do so.


Original Link: https://dev.to/sauravjaiswalsj/automating-git-push-with-just-a-single-bash-command-460n

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To