Git

git hooks post-merge example

#!/bin/bash

# check for modified files
for FILE in $(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD); do
  case "${FILE}" in
    *.json)
      # Repository configuration changed: update configuration
      ~/my_repository/scripts/json_update.sh
      ;;
    cronjobs/crontab)
      # Crontab changed: update user cronjobs
      ~/my_repository/scripts/crontab_update.sh
      ;;
  esac
done

# show repository info
git config -l

# show diff for one file
git diff

# commit only one file
git commit -m 'my comment' path/to/file

# create Git repository
git init

# add all files
git add .

# commit
git commit -m "initial project version"

# list tag
git tag -l

checkout
# checkout over SSH
git clone git@github.com:foo/bar.git

# pull single file
git checkout filename

# pull single file from remote
git checkout origin/master -- path/to/file

# checkout to checkout to specific folder
git clone https://github.com/panticz/installit.git /path/to/folder

# checkout tag
git checkout 1.0.2

# git pull single file
git checkout origin/master -- file_name

# rollback to revision
git checkout 96fe40ded8277725d244aac83c42256ad554cc3b .

# switch branch
git checkout branch_name
git checkout master

# checkout branch
git clone --branch --single-branch []

# test
git reset file/to/overwrite

# search for string
git grep "string/regexp" $(git rev-list --all)

# grep
git grep foo HEAD

# remove last commit
git reset HEAD~1

# reset to latest revision
git reset --hard

git cherry-pick commit1

branch
# diff between branches
git diff master

# show branches
git branch

# push local Git branch to remote master branch
git push origin local_branch_1:master

# delete local branch
git branch -d local_branch_name

# delete remote branch
git push origin :remote_branch_name

# ignore
./.gitignore

# git global setup
git config --global user.name "first_name last_name"
git config --global user.email "user@example.com"

# create a new repository
git clone git@example.com:repository_group/repository_name.git
cd repository_name
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master

# Add existing folder or Git repository
cd existing_folder
git init
git remote add origin git@example.com:repository_group/repository_name.git
git add .
git commit
git push -u origin master