/ Tools



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 "https://github.com/git/git/archive/v2.7.0.tar.gz" | tar zx
cd git-2.7.0
./configure --prefix=/usr
make install --with-curl


git config --global user.name "Myself"
git config --global user.email "my.email@company.com" 

# 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.https://gitlab.prov.io.username my.login
git config --global credential.https://gitlab.prov.io.helper 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 https://github.com/librenms/librenms

mkdir librenms-mibs
cd librenms-mibs
git init
git remote add -f origin https://github.com/librenms/librenms
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