Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/smolijar/git-tips

Tips for forgetful I, so I know all the things I need to, when forced to set up git from scratch in new env.
https://github.com/smolijar/git-tips

Last synced: 2 days ago
JSON representation

Tips for forgetful I, so I know all the things I need to, when forced to set up git from scratch in new env.

Awesome Lists containing this project

README

        

= Git tips
:toc:

Tips for forgetful I, so I know all the things I need to, when forced to set up git from scratch in new env.

```
curl https://raw.githubusercontent.com/grissius/git-tips/master/.gitconfig > ~/.gitconfig && echo "Change your name in ~/.gitconfig"
```

Sit back and let me guide myself.

== Who am I?
```sh
git config --global user.name "John Doe"
git config user.email [email protected]
```

[TIP]
====
*You might want _not_ to set your email globally.*

If working on student/work/personal projects, you might want to use different emails.
If you set it globally, you _will always forget_ to change it on new projects.
This way you will be propted :-)
====

== Editor

Do set up your editor.

```sh
git config --global core.editor vim
```

[TIP]
====
*Use _vim_*

If tempted to use one with GUI, just don't.
Been there, done that, not worth it.
If you can swap between insert and normal mode, save and quit,
you are overqualified to use vim for your commit messages.
Else use other CLI editor.
====

== Custom GUI difftool

image:http://i0.kym-cdn.com/photos/images/original/001/305/222/ae7.gif[]

It might sound like a brand new excellent idea to you, after discovering GPU acc terminal emulators (like link:https://github.com/kovidgoyal/kitty[kitty]) and inline graphical diffs. Same advice applies. But give it a shot you stubborn rabbit.

== Excludes file

. Don't dodge your IDE temp files while staging changes.
. Don't add them into repository `.gitignore`.
Nobody gives a dayum about which editor you use.
. And for the love of god, do not add them.
. Do create personal `.gitignore`!

This is your personal local (unshared) global (over all your local repositories) `.gitignore`.
Use for editor, IDE, system specific files.

```sh
git config --global core.excludesfile '~/.gitignore'
```

NOTE: All config you set is stored in `~/.gitconfig`. You can edit it there as well.

== Aliases

==== Log
Full colorful tree, all refs.
```
ll2 = log --oneline --graph --all --decorate
ll = log --graph --all --decorate --format=format:'%C(bold cyan)%h%C(reset) %C(dim cyan)(%ar)%C(reset)%C(auto)%d%C(reset) %C(white)%s%C(reset) %C(dim white)(%ae) %C(reset)'
```
`ll2` standard, `ll` custom with dates and authors

==== Status
Short (`-s`) removes help and provies just bare summary. Standard provides brief help.
```
st = status -s
sta = status
```

==== Commits
`cian` extremely useful for quick patches hook fallouts etc.
```
ci = commit
cia = commit --amend
cian = commit --amend --no-edit
```

==== Index/remote
```
rs = reset
ad = add
co = checkout
cob = checkout -b
br = branch
pushu = push -u
```

==== Rebasing
```
cp = cherry-pick
rb = rebase
rbi = rebase --interactive
me = merge
```

==== Diffing
```
di = diff
dic = diff --cached
wdi = diff --word-diff --color-words
wdic = diff --cached --word-diff --color-words
```

==== Branch cleanup
Remove all merged branches (link:https://stackoverflow.com/a/6127884/4425335[credit]), except for _standard_ ones.
```
cutbr = "!git branch --merged | egrep -v '(^\\*|master|dev)' | xargs git branch -d"
```

=== Adding aliases

. Add via CLI
+
```sh
git config --global alias.ci commit
```
. Add into `~/.gitconfig`
+
```
[alias]
st = status -s
```