#
GIT
#
When something goes wrong
Flight Rules - Useful directions
#
Useful git settings
Following configuration should be in your $HOME/.gitconfig:
[push]
# prevents your from accidentally pushing to a wrong branch
default = nothing
[alias]
dc = diff --cached
co = checkout
ci = commit
cm = commit -m
st = status
br = branch
lg = !git log --graph --pretty='format:%C(yellow)%h%C(reset) -%C(red)%d%C(reset) %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'
slog = log --oneline
rb = rebase
rbc = rebase --continue
rbi = rebase -i
fap = fetch --all --prune --progress
latest = for-each-ref --sort=-committerdate refs/heads refs/remotes --format='%(committerdate:iso8601) %(refname:short) %(authorname)'
The most useful alias is git fap which fetches the changes from all remotes and at the same time prunes your local copy.
#
Global .gitignore
Adding global gitignore file
$ git config --global core.excludesfile '~/.gitignore'
$ vim ~/.gitignore
File contents:
.idea/
# Mac OS X hidden files
.DS_Store
#
Merge to master
$ git checkout master
$ git merge
$ git merge <your/branch>
$ git push origin master
Delete remote branch
$ git push origin :<your/branch>
Delete local branch
$ git branch -d <your/branch>
#
Rebase Git
$ git fap
$ git rebase origin/master
$ git push -f origin <your/branch>
#
Remove local changes
$ git clean -f -d
$ git checkout -- .
#
Review
console.log
| translate
class=""
Grammarly
<pre> , <code>
#
Stash Git
$ git stash list
$ git stash save "your message here"
$ git stash apply stash@{0}
#
Cherry pick specific commit
$ git cherry-pick c8e153b31
#
Create new branch from another branch
$ git checkout -b new/branch from/branch
#
Delete all branches that you no longer need
Use TAB to select branches that you want to remove. Need to have fzf and xargs installed.
git branch | fzf --multi --bind 'ctrl-a:select-all' | xargs git branch -D