Git Tricks, handy Git commands for everyday use
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
Aliases
[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
-
Set a global
.gitignore
:[core] excludesfile = /home/user/.gitignore
-
Delete local branches that have been removed from remote on fetch/pull:
[fetch] prune = true
-
Gives you extra info when using Git submodules:
[status] submodulesummary = 1
Misc
-
Get a list of Git branches, ordered by most recent commit:
git for-each-ref --sort=-committerdate refs/heads/
-
@
is the same asHEAD
:git show @~3
-
-
refers to the branch you were on before the current one. Use it to checkout the previous branch (source):% git branch master * rs-zenmode-refactor % git checkout master % git checkout -
-
Delete local branches which have already been merged into master (source):
git branch --merged master | grep -v "master" | xargs -n 1 git branch -d
-
Delete all stale tracking branches for a remote:
git remote prune origin