Git Auto Push – Pull Script
The Git Auto Push – Pull Script
Git is a blessing for programmers, it’s well managed version control allows you to properly manage and work on your project individually or in a team. Sometimes the git has the same old add, commit, pull and push work and you need to retype everything. Well using this push-pull script you can be free from unnecessary keystrokes.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
#!/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 |
The above script can be added to a shell script file <git.sh> and the following steps can be taken to make it ususable.
Installation
create the script file and add the above code
1 2 3 4 |
$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
1 2 3 4 5 |
#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 2 3 4 5 6 7 8 |
#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 |