Thursday, May 3, 2012

GIT snippet #2

Aliases Very handfull way to make your console interaction easier. Here we go. Basic:
git config --global alias.go checkout
git config --global alias.st status
git config --global alias.gc commit
git config --global alias.br branch
git config --global alias.gr rebase
git config --global alias.gs stash
git config --global alias.l pull
git config --global alias.p push
Hardcore:
git config --global alias.grm rebase master
git config --global alias.god checkout dev
git config --global alias.gom checkout master
git config --global alias.gmd merge dev
So usual commit-push cycle would be:
git gc -a -m "master"
git gom // checkout master
git l   // pull
git god // checkout dev
git grm // rebase master
git gom // checkout master
git gmd // merge dev
git p   // push
git god // git checkout dev
Want more hardcore? We can write this to bash aliases, just add this lines to ~/.bashrc:
alias gl='git pull'
alias gp='git push'
alias gs='git status'
alias gc='git commit'
alias gcm='git commit -a -m'
alias go='git checkout'
alias gb='git branch'
alias gs='git status'
alias god='git checkout dev'
alias gom='git checkout master'
alias gmd='git merge dev'
alias grm='git rebase master'
alias grc='git rebase --continue'
alias gra='git rebase --abort'
So now our commit-push cycle would be:
gc -a -m "master"
gom // checkout master
gl   // pull
god // checkout dev
grm // rebase master
gom // checkout master
gmd // merge dev
gp   // push
god // git checkout dev
And if you want to automate rebase this action, you can write a bash script:
#!/bin/bash

branch=$1

cd ~/projects/$branch
git checkout dev
git stash
git checkout master
git pull
git checkout dev
git rebase master
if grep -q $commitString <<< $output; then
 git reset HEAD^
fi 
git stash apply
cd "`pwd`"
You can call this script by ./script.sh project_name This script will also rollback if you have rebase conflicts. Then better actually do such an action manually.

No comments:

Post a Comment