sudo yum groupinstall "Development Tools" -y
sudo yum install gettext-devel openssl-devel perl-CPAN perl-devel zlib-devel curl-devel -y
# gettext-devel requires git 1.8 from repository
yum remove git -y
curl -L "" | tar zx
cd git-2.7.0
./configure --prefix=/usr
make install --with-curl


git config --global "Myself"
git config --global "" 

# Pull always rebase instead of merge
git config --global branch.autosetuprebase always
git config --global push.default simple

git config --global color.ui true
git config --global color.status auto
git config --global color.branch auto

git config --global core.editor vim
git config --global merge.tool meld

# If HTTPS with self signed certificate
git config --global http.sslVerify false    

# Cache authentification
git config --global credential. my.login
git config --global credential. cache

Basic git

Add all modification to local repository

git add *
git commit -m "Message"

Remove a file

git rm ./file

Cancel change on a file

git checkout -- ./file

List all branches

git branch -a

New branch

git branch newbranch

Switch on a branc

git checkout newbranch

Push local newbranch to a remote "origin" repository

git push origin newbranch

Shortcut, will create newbranch on origin

git checkout -t origin/newbranch

Send local change to remote (origin by default)

git push


Reminder : c1..c2 means ]c1-c2] means all commit from c1 without c1 to c2 included

Display commit from master not in testing branch

git log testing..master

Last 4 commits

git log HEAD~4..HEAD


Inline diff, word by word instead of line by line

git diff --word-diff

Short status

git status -sb

Find a commit using SHA

git name-rev --name-only 50f3754

Find a commit using searching a regexpr in message, here looking for Merge

git show :/^Merge

Change last commit message

git commit --amend -m "New message"

Sparse checkout

Sparse checkout is about pulling only desired stuff. For this example I just wanna grab directory mibs from repo

mkdir librenms-mibs
cd librenms-mibs
git init
git remote add -f origin
git config core.sparseCheckout true
echo "mibs" >> .git/info/sparse-checkout
git pull origin master

Everything in .git/info/sparse-checkout is included. Add ! to exclude, hence for getting everything minus some folder