Share a git abbreviation script
git shorthand command, add linux,mac alias
Usage method:
. / gsh [command name] [parameter, optional]
set sets user name and mailbox, 1: name, 2: mailbox
init Sets git Concise Command
gst: Code change status, git status
gd: View current code changes, git diff, git diff Branch 1 branch 2
Gam: [gam comment] code submitted to local warehouse: git commit-am "comment"
Gpu: [gpu remote branch name] associated with remote warehouse: git push-u origin branch name
Gp: [gp] Push to remote warehouse: git push
Gl: [gl] pull remote warehouse code: git pull
Gb: [gb new branch name] Create and switch new branch: git checkout-b new branch name
Gm: [gm branch name] merged branch: git merge branch name
Gcm: [gcm target branch name] switch branches, update and merge: git check out branch name B & git pull & git merge branch name A
gsave saves temporary modification files, git stash save
gpop restores temporarily modified files, git stash pop
glg view git log. git log
#!/usr/bin/env bash # # # # __----~~~~~~~~~~~------___ # . . ~~//====...... __--~ ~~ # -. \_|// |||\\ ~~~~~~::::... /~ # ___-==_ _-~o~ \/ ||| \\ _/~~- # __---~~~.==~||\=_ -_--~/_-~|- |\\ \\ _/~ # _-~~ .=~ | \\-_ '-~7 /- / || \ / # .~ .~ | \\ -_ / /- / || \ / # / ____ / | \\ ~-_/ /|- _/ .|| \ / # |~~ ~~|--~~~~--_ \ ~==-/ | \~--===~~ .\ # ' ~-| /| |-~\~~ __--~~ # |-~~-_/ | | ~\_ _-~ /\ # / \ \__ \/~ \__ # _--~ _/ | .-~~____--~-/ ~~==. # ((->/~ '.|||' -_| ~~-/ , . _|| # -_ ~\ ~~---l__i__i__i--~~_/ # _-~-__ ~) \--______________--~~ # //.-~~~-~_--~- |-------~~~~~~~~ # //.-~~~--\ # Dragon bless # Code without BUG! # ########################################################################################################### # git shorthand command, add linux,mac alias # # Usage method: # . / gsh [command name] [parameter, optional] # # set sets user name and mailbox, 1: name, 2: mailbox # init Sets git Concise Command # # gst: Code change status, git status # gd: View current code changes, git diff, git diff Branch 1 branch 2 # Gam: [gam comment] code submitted to local warehouse: git commit-am "comment" # Gpu: [gpu remote branch name] associated with remote warehouse: git push-u origin branch name # Gp: [gp] Push to remote warehouse: git push # Gl: [gl] pull remote warehouse code: git pull # Gb: [gb new branch name] Create and switch new branch: git checkout-b new branch name # Gm: [gm branch name] merged branch: git merge branch name # Gcm: [gcm target branch name] switch branches, update and merge: git check out branch name B & git pull & git merge branch name A # gsave saves temporary modification files, git stash save # gpop restores temporarily modified files, git stash pop # glg view git log. git log # # # Editing time: 2019-05-24, author: Baili, small station: sgfoot.com, bbs.sgfoot.com ############################################################################################################### cate=$1 #Operation name second=$2 # First parameter third=$3 # Second parameter #Default value default_name="Hundred Li" default_email="sgfoot2020@gmail.com" # Defining variables tmp_file=/tmp/git.branch # Get the branch name function git.branch { br=`git branch | grep "*"` touch /tmp/git.branch echo ${br/* /} > $tmp_file } # Initialization value function git.init { git config --global alias.st status git config --global alias.df diff git config --global alias.co checkout git config --global alias.cb 'checkout -b' git config --global alias.ci commit git config --global alias.br branch git config --global alias.mg merge git config --global alias.save 'stash save' git config --global alias.pop 'stash pop' git config --global alias.un 'reset HEAD' git config --global alias.last 'log -1' git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit" git config -l } # Display execution status function showStatus { if [ $? -eq 0 ];then echo "Successful implementation" else echo "Execution failure" fi } # Show details of the last submission function showLast { count=$1 show_count=${count:-1} git log -$show_count --stat --graph --oneline --relative-date --abbrev-commit -p --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' } # Show logs in a concise way function showLog { git log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit } #New alias for zsh function create_zshrc { #Copy the current script to / usr/local/sbin gsh_file=/usr/local/sbin/gsh basepath=$(cd `dirname $0`; pwd) filename=$(basename $0) gsh=${basepath}/${filename} git_alias=~/.zshrc #check is=`cat $git_alias |grep "alias gst"` if [ -n "$is" ];then echo "Installed" exit 0 fi echo "alias gst='$gsh gst'" >> $git_alias echo "alias gam='$gsh gam'" >> $git_alias echo "alias gd='$gsh gd'" >> $git_alias echo "alias gpu='$gsh gpu'" >> $git_alias echo "alias gp='$gsh gp'" >> $git_alias echo "alias gl='$gsh gl'" >> $git_alias echo "alias gb='$gsh gb'" >> $git_alias echo "alias gm='$gsh gm'" >> $git_alias echo "alias gcm='$gsh gcm'" >> $git_alias echo "alias gsave='$gsh gsave'" >> $git_alias echo "alias gpop='$gsh gpop'" >> $git_alias echo "alias glg='$gsh glg'" >> $git_alias echo "alias gset='$gsh gset'" >> $git_alias } #New alias for. bash_profile function create_profile { #Copy the current script to / usr/local/sbin gsh_file=/usr/local/sbin/gsh basepath=$(cd `dirname $0`; pwd) filename=$(basename $0) gsh=${basepath}/${filename} git_alias=~/.bash_profile #check is=`cat $git_alias |grep "alias gst"` if [ -n "$is" ];then echo "Installed" exit 0 fi echo "alias gst='$gsh gst'" >> $git_alias echo "alias gam='$gsh gam'" >> $git_alias echo "alias gd='$gsh gd'" >> $git_alias echo "alias gpu='$gsh gpu'" >> $git_alias echo "alias gp='$gsh gp'" >> $git_alias echo "alias gl='$gsh gl'" >> $git_alias echo "alias gb='$gsh gb'" >> $git_alias echo "alias gm='$gsh gm'" >> $git_alias echo "alias gcm='$gsh gcm'" >> $git_alias echo "alias gsave='$gsh gsave'" >> $git_alias echo "alias gpop='$gsh gpop'" >> $git_alias echo "alias glg='$gsh glg'" >> $git_alias echo "alias gset='$gsh gset'" >> $git_alias } help() { if [ "$1" = "h" ];then echo $2 exit 0 fi } # case operation case $cate in create) # create a file if [ $2 -eq 1 ];then echo "Yes bash_profile New Alias" create_profile && showStatus else echo "Yes zshrc New Alias" create_zshrc && showStatus fi ;; init) #Initialization echo "At first git Concise command" git.init && showStatus ;; set) help $second "Setting up git Submitted username and mailbox address" echo "Setting up git Submitted username and mailbox address" git config --global user.name $second git config --globaluser.email $third showStatus ;; my) help $second "Setting up git Submitted username and mailbox address" echo "Setting up git Submitted username and mailbox address" git config user.name $default_name git config user.email $default_email showStatus ;; gst) # View state git status && echo $? ;; gf) # Contrast changes, support version comparison, example gf need to compare the branch name (note: green font is added code, red is deleted code) if [ "$second" = "h" ];then echo "Contrast change, Support version comparison,example gf Branch names to be compared(notes:Green fonts are added code,Red is the deleted code)" exit 0 fi if [ -n "$second" ];then git.branch local_branch=`cat $tmp_file` git diff $second $local_branch else git diff fi ;; gam) # Add, submit code to local if [ -z "$second" ];then echo "Please write your wonderful remarks.,as: This is a generation of baking code.!!!, Code name:(nb)" exit 0 fi if [ "$second" = "nb" ];then second="fix:TODO This is nb code" fi git add -A && git commit -m "$second" && showLast && showStatus ;; gpu) # Submit code remotely and associate remote warehouse git push -u origin $second && showStatus ;; gp) # Submit code to remote if [ -n "$second" ];then git push origin $second && showStatus else git push && showStatus fi ;; gl) # Pull code if [ -n "$second" ];then git pull origin $second && showStatus else git pull && showStatus fi ;; gb) # Create and switch new branches git checkout -b $second && showStatus ;; gm) # Merge code if [ -z "$second" ];then git.branch current_branch=`cat $tmp_file` echo "Please fill in the name of the branch that needs to be merged.,eg: If fill in A Branch name, Usage: git merge A ,representative A Branches merged into $current_branch" exit 0 fi git merge $second && showStatus ;; gcm) # Switch branches and merge code if [ -z "$second" ];then echo "Please keep up with the branch names that need to be merged" exit 0 fi git.branch old_branch=`cat $tmp_file` git checkout $second && git pull && git merge $old_branch && git push && git checkout $old_branch && showStatus ;; glg) # Viewing logs in a concise way showLog ;; gg) # See which files in the log have been changed git log --graph --stat --color --abbrev-commit --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' ;; gcode) # View the specific code for log modifications git log --stat --graph --oneline --relative-date --abbrev-commit -p --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' ;; gsave) # Modification of temporary items git stash save && showStatus ;; gpop) # Take out temporary data git stash pop && showStatus ;; *) echo "Usage $0 {init|set| gst|gam|gpu|gp|gl|gb|gm|gcm|glg|gg|gcode|gsave|gpop}" exit 1 ;; esac