Skip to content

Instantly share code, notes, and snippets.

@guicheffer
Last active June 8, 2018 01:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guicheffer/14f4c1ce0257fc618448 to your computer and use it in GitHub Desktop.
Save guicheffer/14f4c1ce0257fc618448 to your computer and use it in GitHub Desktop.
# https://gist.github.com/codexico/2a34c0d599f3af93b46f
[color]
# Use colors in Git commanfds that are capable of colored output when
# outputting to the terminal. (This is the default setting in Git ≥ 1.8.4.)
ui = auto
[color "branch"]
current = yellow reverse
local = yellow
remote = green
[color "diff"]
meta = yellow bold
frag = magenta bold # line info
old = red # deletions
new = green # additions
[color "status"]
added = yellow
changed = green
untracked = cyan
[core]
editor = vim
# Use custom `.gitignore` and `.gitattributes`
excludesfile = ~/.gitignore
attributesfile = ~/.gitattributes
[user]
name = João Guilherme
email = hi@guicheffer.me
[alias]
# List all aliases, only the names
alias = !git config --list | grep 'alias\\.' | sed 's/alias\\.\\([^=]*\\)=\\(.*\\)/\\1/' | sort;
# List all aliases, names and commands
aliases = !git config --list | grep 'alias\\.' | sed 's/alias\\.\\([^=]*\\)=\\(.*\\)/\\1\\\t\\2/' | sort;
# Clone a repository including all submodules
cloneall = clone --recursive
# Where it is?
url = remote -v;
##########
# Logs and infos
##########
# Who contributed and how much
who = shortlog -sne;
# Show last commit
last = log -1 HEAD;
# Last tag
lasttag = describe --tags --abbrev=0;
# View abbreviated SHA, description, and history graph of the latest 20 commits
l = log --graph --abbrev-commit --pretty=oneline -n 20;
# View the SHA, description, date, author and history graph
# Example:
# * 66a2a64 - comment (20 hours ago) <USER1>
# * 6a7206f - Merge branch 'develop' into very-cool-feature (21 hours ago) <USER2>
# |\
# | * 1748c5f - comment (21 hours ago) <USER2>
# | * e3a42a1 - comment (21 hours ago) <USER2>
# * 2667f01 - comment (2 days ago) <USER3>
# * 7f5722d - comment (2 days ago) <USER1>
#
history = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset';
# View the SHA, description, date, and history graph of my commits
# Example:
# * 66a2a64 - comment (20 hours ago) <USER1>
# * 6a7206f - Merge branch 'develop' into very-cool-feature (21 hours ago) <USER2>
# |\
# | * 1748c5f - comment (21 hours ago) <USER2>
# | * e3a42a1 - comment (21 hours ago) <USER2>
# * 2667f01 - comment (2 days ago) <USER3>
# * 7f5722d - comment (2 days ago) <USER1>
#
mylog = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --author="$(git config USER.name)";
# List contributors with number of commits
contributors = shortlog --summary --numbered;
# Show verbose output about tags
tags = tag -l
##########
# Status
##########
# View the current working tree status using the short format
s = status -s;
# Diff
d = diff --patch-with-stat;
# Show the diff between the latest commit and the current state
d = !"git diff-index --quiet HEAD -- || clear; git --no-pager diff --patch-with-stat"
# `git di $number` shows the diff between the state `$number` revisions ago and the current state
di = !"d() { git diff --patch-with-stat HEAD~$1; }; git diff-index --quiet HEAD -- || clear; d"
##########
# Commits
##########
# lazy alias
c = commit;
# Commit all changes
ac = !git add . && git add -u && git commit -a;
# add and commit with message, dont need quotation marks
# Example:
# git acm message without quotes
acm = "!f() { git add . && git commit -m \"$(echo $@)\"; }; f";
# Amend the currently staged files to the latest commit
amend = commit --amend --reuse-message=HEAD
# mark file as unchanged to prevent commits
assume = git update-index --assume-unchanged;
assumeall = "!git st -s | awk {'print $2'} | xargs git assume"
# remove mark file as unchanged
unassume = git update-index --no-assume-unchanged;
unassumeall = "!git assumed | xargs git update-index --no-assume-unchanged"
# Interactive rebase with the given number of latest commits
reb = "!r() { git rebase -i HEAD~$1; }; r"
##########
# Pull, Push
##########
# pull this branch
get = !git pull origin $(git rev-parse --abbrev-ref HEAD);
# Pull in remote changes for the current repository and all its submodules
pullall = !"git pull origin $(git rev-parse --abbrev-ref HEAD); git submodule foreach git pull origin master"
# push this branch
post = !git push origin $(git rev-parse --abbrev-ref HEAD);
# pull and push this branch
update = "!f() { BRANCH=$(git rev-parse --abbrev-ref HEAD); git s && git pull origin ${BRANCH} && git push origin ${BRANCH}; }; f";
##########
# Deploys
##########
# update develop
dev-deploy = !git pull origin develop && git push origin develop;
# update this branch and send to another branch, and return to this branch
mergeto = "!f() { BRANCH=$(git rev-parse --abbrev-ref HEAD); git pull origin ${BRANCH} && git push origin ${BRANCH} && git checkout $1 && git pull origin $1 && git merge ${BRANCH} && git push origin $1 && git checkout ${BRANCH}; }; f";
# update this branch and send to develop and another branch (release), and return to this branch
#
# another
# branch develop branch
# |
# \
# |
# \
# |
branch-deploy = "!f() { BRANCH=$(git rev-parse --abbrev-ref HEAD); git pull origin ${BRANCH} && git push origin ${BRANCH} && git checkout develop && git pull origin develop && git merge ${BRANCH} && git push origin develop && git checkout $1 && git pull origin $1 && git merge develop && git push origin $1 && git checkout ${BRANCH}; }; f";
##########
# Branchs
##########
# lazy alias
b = branch;
co = checkout;
# create branch local and remote
create = "!f() { git checkout -B $1 && git push origin $1; }; f";
# Switch to a branch, creating it if necessary
go = "!f() { git checkout -b \"$1\" 2> /dev/null || git checkout \"$1\"; }; f"
# update branchs
branchs = !git fetch --all && git fetch -p && git branch -a;
# change to another branch and update
go = "!f() { git checkout $1 && git pull origin $1; }; f";
# remove branchs that dont exist on remote
# (you should be on one existing branch)
# TODO: 'git remote prune origin' does the same?
delete-not-on-remote-branches = !git branch -a | egrep -v 'origin|master|develop' | xargs -n1 git branch -d;
# force remove branchs that dont exist on remote
# (you should be on one existing branch)
force-delete-not-on-remote-branches = !git branch -a | egrep -v 'origin|master|develop' | xargs -n1 git branch -D;
# remove branchs merged on master
# TODO: dont remove develop if it is sync with master
delete-merged-branches = !git branch --merged master | grep -v 'master' | xargs -n 1 git branch -d;
# force remove branchs merged on master
force-delete-merged-branches = !git branch --merged master | grep -v 'master' | xargs -n 1 git branch -D;
##########
# Undo
##########
# Undo a `git push`
undopush = push -f origin HEAD^:master;
# Undo merge
undomerge = reset --hard HEAD@{1};
# Undo changes not commited
undo = reset --hard;
# Undo last commit and remove from stage
# Example
# git unstage file1 file2 ...
unstage = reset HEAD -- #file;
##########
# Merge
##########
# merge and use mine
ours = "!f() { git checkout --ours $@ && git add $@; }; f";
# merge and use theirs
theirs = "!f() { git checkout --theirs $@ && git add $@; }; f";
##########
# Find
##########
find = "!f() { git rev-list --all | xargs git grep $1; }; f";
# Find branches containing commit
fb = "!f() { git branch -a --contains $1; }; f"
# Find tags containing commit
ft = "!f() { git describe --always --contains $1; }; f"
# Find commits by source code
fc = "!f() { git log --pretty=format:'%C(yellow)%h %Cblue%ad %Creset%s%Cgreen [%cn] %Cred%d' --decorate --date=short -S$1; }; f"
# Find commits by commit message
fm = "!f() { git log --pretty=format:'%C(yellow)%h %Cblue%ad %Creset%s%Cgreen [%cn] %Cred%d' --decorate --date=short --grep=$1; }; f"
#===========================================
# I really dont recommend powerful commands with one letter only
#===========================================
# a = add .;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment