💡Git

The Basics

Github flow
  • Model development and version control in article

Main CLI commands
  • git --version

  • git config

  • git config --global user.name = 'Klenin Maksim';

  • git config --global user.email = 'maksim_klenin_99@mail.ru';

  • git init

  • git add .

  • git commit -m "Commit"

  • git log

  • git status

  • git diff

  • git reset --hard HEAD

  • git show aa380fa8cc89695a3921114efc4dcde92ee09284

  • git checkout -b new-user-feature

  • git merge new-user-feature

  • git branch -d new-user-feature

  • git reset

  • git pull

Stash
  • git stash

  • git stash list

  • git stash apply

  • git stash apply stash@{0}

  • git stash drop

Aliases
  • git config --global alias.s status

  • git s

  • git config --global --unset alias.s

Logs

Beautiful log:

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 --branches"
git lg

Digging Deeper

Add hook pre-commit

Laravel pint:

  • touch .git/hooks/pre-commit

  • vim .git/hooks/pre-commit

#!/bin/sh
files=$(git diff --cached --name-only --diff-filter=ACM -- '*.php');
vendor/bin/pint $files -q

git add $files
  • chmod ug+x .git/hooks/*

Edit time in commit
  • git commit --amend --no-edit --date=now - Last commit to current time

Add multiple ssh keys for GitHub
ssh-keygen -t rsa -C "your_email@youremail.com"
~/.ssh/id_rsa_activehacker
~/.ssh/id_rsa_jexchan
eval `ssh-agent -s`
ssh-add ~/.ssh/id_rsa_activehacker
ssh-add ~/.ssh/id_rsa_jexchan
vim .ssh/config
#activehacker account
Host github.com-activehacker
	HostName github.com
	User git
	IdentityFile ~/.ssh/id_rsa_activehacker

#jexchan account
Host github.com-jexchan
	HostName github.com
	User git
	IdentityFile ~/.ssh/id_rsa_jexchan

Last updated