Skip to content

Instantly share code, notes, and snippets.

@ivanrodjr
Last active June 20, 2021 15:10
Show Gist options
  • Save ivanrodjr/8cfa592604d6385812b5ce02b705db54 to your computer and use it in GitHub Desktop.
Save ivanrodjr/8cfa592604d6385812b5ce02b705db54 to your computer and use it in GitHub Desktop.
Git config
[user]
name = your name
email = your githib email or the no reply
[color]
# Enable colors in color-supporting terminals
ui = auto
[init]
templatedir = ~/.git-templates
defaultBranch = main
[alias]
# List available aliases
aliases = !git config -l | grep alias | cut -c 7-
# Add the names you prefer to the aliases, whats after the = is the important part
# Display state of working dir
s = status
# Add files to the staging area
a = add .
# Creates a commit and opens default editor e.g. vim
c = commit
# Creates a commit, bypasses default editor and adds the message e.g. git cm "Add whatever..."
cm = commit -m
# Checkout a specific branch
co = checkout
# Create branch and checkout
cob = checkout -b
# Show all remote branches
remotes = remote -v
# Show all branches
ab = branch -av
# Delete branch
db = branch -D
# Deletes all branches except master or main (change the name) CAREFUL
deleteAll = !git branch | grep -v master | xargs git branch -D
# Rename current branch
rename = branch -M
# Disables push to upstream
disable = remote set-url --push upstream DISABLED
# Log with super powers
lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'
# Log that shows the last 10 commits...change the number for more
lgs = log -10 --color=always --all --graph --topo-order --pretty='%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative
# Push current feature branch
pb = !git push --set-upstream origin \"$(git rev-parse --abbrev-ref HEAD)\"
# Ensure that force-pushing won't lose someone else's work (only mine).
push-with-lease = push --force-with-lease
# Rebase won’t trigger hooks on each "replayed" commit.
# This is an ugly hack that will replay each commit during rebase with the
# standard `commit` command which will trigger hooks.
rebase-with-hooks = rebase -x 'git reset --soft HEAD~1 && git commit -C HEAD@{1}'
# List local commits that were not pushed to remote repository
review-local = !git lg @{push}..
# Edit last commit message
amend = commit --amend
# Undo last commit but keep changed files in stage
undo = reset --soft HEAD~1
# Remove file(s) from Git but not from disk
untrack = rm --cached
# Deletes any local branch which has been deleted from the remote
fp = fetch --prune
# Ensures that when you stash, you catch the new files you haven’t caught with a git add yet. a.k.a stash-all
sa = stash save --include-untracked
# Pop the stash in the current branch
sp = stash pop
# Removes the saved stash
sd = stash drop
# Fetch origin
fo = fetch origin
# Fetch upstream
fu = fetch upstream
# CAREFUL WITH BELOW COMMANDS >> See Rebase docs
# Rebase origin/master
ro = rebase origin/master
# Rebase upstream/master
ru = rebase upstream/master
# Rebase master
rem = rebase master
[status]
# Shows you all of the files underneath that new directory during a git status (slow in very large repos)
showUntrackedFiles = all
[commit]
# Git commit default message template
template = ~/.git-templates/.git-commit-msg-template.txt
# Prevent commit status from attaching below the custom template
status = false
# Ensures that all of your commits are signed by your GPG key.
gpgsign = true
[merge]
# Get an error unless every merge is fast-forward
ff = only
# Intended changes from the ‘left’ and the intended changes from the ‘right, with third section of the original changes before ‘left’ and ‘right’ tried to change it.
conflictstyle = diff3
[core]
# Hooks directory
hooksPath = ~/.git-templates/hooks
# Global ignore file
excludesfile = ~/.gitignore_global
[diff]
# Use better, descriptive initials (c, i, w) instead of a/b.
mnemonicPrefix = true
# Show renames/moves as such
renames = true
# When using --word-diff, assume --word-diff-regex=.
wordRegex = .
# Display submodule-related information (commit listings)
submodule = log
[log]
# Use abbrev SHAs whenever possible/relevant instead of full 40 chars
abbrevCommit = true
# Automatically --follow when given a single path
follow = true
# Disable decorate for reflog
# (because there is no dedicated `reflog` section available)
decorate = false
[color "branch"]
# Blue on black is hard to read in git branch -vv: use cyan instead
upstream = cyan
[color "status"]
added = green
changed = yellow
untracked = red
[gpg]
program = /usr/local/bin/gpg
[push]
default = simple
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment