Skip to content

Instantly share code, notes, and snippets.

@Adam--
Last active July 28, 2022 14:27
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 Adam--/924c023392703df2e7e143dd2f10925d to your computer and use it in GitHub Desktop.
Save Adam--/924c023392703df2e7e143dd2f10925d to your computer and use it in GitHub Desktop.
Git config
[alias]
# Lists all aliases
alias = config --get-regexp ^alias\\.
# Quote a command to allow it to be used as a git alias
quote-string = "!read -r l; printf \\\"!; printf %s \"$l\" | sed 's/\\([\\\"]\\)/\\\\\\1/g'; printf \" #\\\"\\n\" #"
# Gets information about a repo
url = config remote.origin.url
branch-name = rev-parse --abbrev-ref HEAD
# Pretty log with graph
l = !git status && git log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit -15
graph = l --all --first-parent -30
# Publishes a branch by pushing it to the origin
publish = !git push -u origin $(git branch-name)
# Restores a deleted file using the last committed version
restore = !git checkout $(git rev-list -n 1 HEAD -- "$1")^ -- "$1"
# Squashes a given number of commits starting at HEAD
squash = "!f(){ git reset --soft HEAD~${1} && git commit --edit -m\"$(git log --format=%B --reverse HEAD..HEAD@{1})\"; };f"
# Moves a local repo url to a new url
move = "!f() { originalUrl=$(git url);echo "Moving repo from $originalUrl to $1";git remote set-url origin $1; };f"
# Pretty log of incoming commits
incoming = !git fetch && git l ..origin/$(git branch-name)
# Force push with lease
pushf = push --force-with-lease
# Cleans up after finishing a git-flow branch
cleanup-flow = !git remote prune origin && git checkout develop && git pull --ff-only && git branch -d $1
# Cleans up after merging a PR for a branch
cleanup = "!f() { branchName=${1-$(git branch-name)}; echo "Cleaning up $branchName"; git remote prune origin; git checkout master; git pull --ff-only; git branch -d $branchName; git l; }; f"
# Deletes local branches that have already been merged with master
delete-merged-branches = "!git branch --merged | egrep -v \"(^\\*|master|develop)\" | xargs git branch -d #"
# Deletes local branches that have a missing remote, defaults to a -d, pass -D to force delete
delete-branches-missing-remote = "!git branch -vv | grep ': gone]'| grep -v \"\\*\" | awk '{ print $1 }' | xargs -r git branch ${1--d} #"
# Check if rebased and merged with master
check-rebase-merged = "!f() { branchName=${1-$(git branch-name)}; git fetch; git log --oneline --cherry origin/master...$branchName; };f"
# Quickly ammend the previous commit
amend = commit -a --amend --no-edit
[core]
# Use micro as the default editor
# editor = micro
# Use VS Code as teh default editor
editor = "code.cmd --wait"
excludesfile =
[pull]
# Rebase instead of merging when pulling
rebase = true
[help]
autocorrect = 1
[rebase]
autosquash = true
[rerere]
enabled = true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment