til/Applications/Essential/git.md

67 lines
798 B
Markdown
Raw Normal View History

2020-05-08 18:48:34 +00:00
# Git
2020-02-17 17:28:12 +00:00
2020-07-07 18:11:14 +00:00
## Config
2020-06-12 20:00:31 +00:00
Aliases:
```sh
git config --global alias.br branch
git config --global alias.ci commit
2020-07-07 18:11:14 +00:00
git config --global alias.co checkout
git config --global alias.df diff
2020-06-12 20:00:31 +00:00
git config --global alias.st status
git config --global alias.logo 'log --pretty=oneline'
```
2020-05-09 18:30:08 +00:00
Use neovim when commit:
```sh
git config --global core.editor nvim
```
2020-07-07 18:11:14 +00:00
## Commands
2020-02-17 17:28:12 +00:00
Prefer rebase when pull:
```sh
git pull --rebase
```
Clean outdated branches:
```sh
2020-03-19 03:04:02 +00:00
git fetch --prune
2020-02-17 17:28:12 +00:00
```
2020-07-07 18:11:14 +00:00
Push force **safely**:
2020-02-17 17:28:12 +00:00
```sh
2020-03-19 03:04:02 +00:00
git push --force-with-lease
2020-02-17 17:28:12 +00:00
```
2020-03-28 15:02:25 +00:00
Rewrite history by changing last `x` commits :
2020-02-28 20:51:00 +00:00
```sh
2020-03-19 03:04:02 +00:00
git rebase -i HEAD~x
2020-02-28 20:51:00 +00:00
```
2020-07-10 04:18:24 +00:00
Squash last `x` commits to 1 commit:
```sh
git reset HEAD~x
git add -A
git commit
```
Cleanup unnecessary files:
```sh
git gc
```
2020-07-10 05:45:14 +00:00
Find common ancestor:
```sh
git merge-base A B
```