The Git Auto Pull Push Script

Try Fast Read
0
0



The Git Auto Pull Push Script

Working with git is a huge plus point, it’s easier to track, merge and revert the changes. Working with git is a great way to have lots of people working on the same codes. Everything is a plus point, but if you are lazy like me and have to do 1000s of push and pull everyday, you’d end up being frustrated, very very frustrated. Hence I wrote a script that shows the git status, asks you if you want to continue pushing the data, it auto runs pull script before pull so basically this “the git auto pull push script” saves you time and keystroke.

 

 

#!/bin/zsh
if [ "$#" -lt 1 ] 
  then
  echo "No commit message given give one now"
  read a 
else
  a=$1
fi
if [ "$#" -eq 2 ] 
  then
  b=$2 
else
  b="master"
fi
git status
read -p "Do you want to push: " yn
case $yn in
 [Yy]* ) git add -A;git commit -m "${a}";git pull origin $b;git push origin $b; break;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no:: ";;
esac

So basically what the above script does is it shows you the current status of git, files that have been modified/created/deleted then it asks you if you want to continue to push the data. If yes it adds, commits with your given message and pulls the changes from server and finally runs the push. It also support branch push pull.

Installation
create the script file and add the above code

$vim /usr/bin/git.sh
chmod +x /usr/bin/git.sh
#Now you can run the script by 
$sh /usr/bin/git.sh

Using Alias

#open your shell config file ~/.bashrc for bash shell; ~/.zshrc for z shell
$vim ~/.bashrc
#Now add the following line at the bottom
alias gitpush="sh /usr/bin/git.sh"
#now you can just use gitpush to run the above script

Usuage

#1 Passing Parameters or when needed branch
$gitpush "My commit Message" "optional_branch_name"
#eg1: $gitpush "Fixed the header file" //push fixed the header file commit to master branch
#eg2: $gitpush "Fixed the header file" "development"  //push fixed the header file commit to development branch

#2 Without Parameter
$gitpush
#write your commit message when prompted

Post navigation