Last active
July 20, 2021 11:27
-
-
Save berikv/e1881a277c83a5af5b4126bcf0b82000 to your computer and use it in GitHub Desktop.
Some convenient and readable git aliases
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Paste these lines into your ~/.bashrc or other shell initialisation script | |
# Note that for most of these, your gitconfig has to have the aliasses from the .gitconfig in this gist | |
alias co='git checkout' | |
alias st='git status' | |
alias add='git add' | |
alias commit='git commit' | |
# Amend anything that is staged | |
alias amend='git commit --amend --no-edit' | |
# Pretty log | |
alias lg='git lg' | |
# Show branches | |
alias br='git br' | |
alias mkbranch='git mkbranch' | |
alias rmbranch='git rmbranch' | |
alias mvbranch='git mvbranch' | |
alias stashes='git stashes' | |
alias unstaged='git unstaged' | |
alias staged='git staged' | |
alias unstage='git unstage' | |
alias stash-unstaged='git stash-unstaged' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[alias] | |
# Shows the git log one commit per line, nicely formatted | |
logline = log --color --graph --pretty=format:'%Cred%h%Creset%C(yellow)%d%Creset -%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit | |
# Shows the past 10 commits of the current branch, on per line | |
lg = "!git --no-pager logline -10" | |
# Shows the commits in the current branch that are not in the master branch | |
lgm = "!git --no-pager logline master..HEAD" | |
# Show for each commit: short commit hash, branches / tags, commit message, time since commit was made, author | |
lg = log --color --graph --pretty=format:'%Cred%h%Creset%C(yellow)%d%Creset -%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit | |
# Show for each local branch: short commit hash, branch name, commit message, time since commit was made | |
br = for-each-ref --sort=-committerdate refs/heads/ --format='%(HEAD) %(color:yellow)%(objectname:short)%(color:reset) %(refname:short): %(contents:subject) (%(color:green)%(committerdate:relative)%(color:reset))' | |
# Show for each stash: short commit hash, based on which branch / commit, message of the commit, time since stash was made | |
stashes = reflog show --pretty=format:'%Cred%h%Creset%C(yellow)%d%Creset -%Creset %s %Cgreen(%cr)' --abbrev-commit stash | |
# Make a branch named ... | |
mkbranch = checkout -b | |
# Remove branch named ... | |
rmbranch = branch -D | |
# Move (rename) branch named ... to ... | |
mvbranch = branch -m | |
# List changed files and nothing else | |
unstaged = diff --name-only | |
changed-files = diff --name-only | |
# Show staged files and nothing else | |
staged = diff --staged -w | |
# Unstage ... | |
unstage = reset HEAD -- | |
# Make a stash from all changes that are not staged | |
stash-unstaged = !git commit -m'git-stash-unstaged WIP' && git add . && git stash && git reset --soft HEAD~1 | |
# git rebase -i master: Very usefull when reworking stacked commits in a pull request | |
rim = rebase -i master | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment