blob: 2c4a388426a470ceeb385d98cdb344b038547e8a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
Based on https://gitlab.com/gitlab-org/gitlab-ce/issues/5986 here is an outline.
---
A pack of Git tricks that will leverage your Git-fu.
## Introduction
## Oh-my-zsh Git plugin
- https://github.com/robbyrussell/oh-my-zsh/wiki/Plugin:git
- https://github.com/robbyrussell/oh-my-zsh/blob/master/plugins/git/git.plugin.zsh
## Git extras
Enhance Git with more commands
- https://github.com/tj/git-extras
## Aliases
```ini
[alias]
lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit --date=relative
lol = log --graph --decorate --pretty=oneline --abbrev-commit
```
## `.gitconfig` on steroids
- https://github.com/thoughtbot/dotfiles/blob/master/gitconfig
- https://github.com/thoughtbot/dotfiles/pull/377
---
1. Set a global `.gitignore`:
```ini
[core]
excludesfile = /home/user/.gitignore
```
1. Delete local branches that have been removed from remote on fetch/pull:
```ini
[fetch]
prune = true
```
1. Gives you extra info when using Git submodules:
```ini
[status]
submodulesummary = 1
```
## Misc
1. Get a list of Git branches, ordered by most recent commit:
```
git for-each-ref --sort=-committerdate refs/heads/
```
1. `@` is the same as `HEAD`:
```
git show @~3
```
1. `-` refers to the branch you were on before the current one.
Use it to checkout the previous branch ([source][dash]):
```sh
% git branch
master
* rs-zenmode-refactor
% git checkout master
% git checkout -
```
1. Delete local branches which have already been merged into master
([source][del-merged]):
```
git branch --merged master | grep -v "master" | xargs -n 1 git branch -d
```
1. Delete all stale tracking branches for a remote:
```
git remote prune origin
```
[del-merged]: http://stevenharman.net/git-clean-delete-already-merged-branches
[dash]: https://twitter.com/holman/status/530490167522779137
|