# Git

## The Basics

<details>

<summary>Github flow</summary>

* Model development and version control in [article](https://bitworks.software/2019-03-12-gitflow-workflow.html)

</details>

<details>

<summary>Main CLI commands</summary>

* `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`

</details>

<details>

<summary>Stash</summary>

* `git stash`
* `git stash list`
* `git stash apply`
* `git stash apply stash@{0}`
* `git stash drop`

</details>

<details>

<summary>Aliases</summary>

* `git config --global alias.s status`
* `git s`
* `git config --global --unset alias.s`

</details>

<details>

<summary>Logs</summary>

Beautiful log:

```bash
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
```

</details>

## Digging Deeper

<details>

<summary>Add hook pre-commit</summary>

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/*`

</details>

<details>

<summary>Edit time in commit</summary>

* `git commit --amend --no-edit --date=now` - Last commit to current time

</details>

<details>

<summary>Add multiple ssh keys for GitHub</summary>

```bash
ssh-keygen -t rsa -C "your_email@youremail.com"
```

```
~/.ssh/id_rsa_activehacker
~/.ssh/id_rsa_jexchan
```

```bash
eval `ssh-agent -s`
```

```bash
ssh-add ~/.ssh/id_rsa_activehacker
ssh-add ~/.ssh/id_rsa_jexchan
```

```bash
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
```

</details>



