Skip to content

Instantly share code, notes, and snippets.

@donnfelker
Last active December 3, 2023 14:16
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save donnfelker/764ffa606e2a5a7bfa5c236e1908297d to your computer and use it in GitHub Desktop.
Save donnfelker/764ffa606e2a5a7bfa5c236e1908297d to your computer and use it in GitHub Desktop.
Git and Fish
[user]
name = Your Name
email = you@youremail.com
[alias]
A = add -A
a = add
aa = add --all
ae = add --edit
ai = add --interactive
amend = commit --amend -C HEAD
ap = add --patch
au = add --update
authors = "!git log --pretty=format:%aN | sort | uniq -c | sort -rn"
b = branch
c = commit
ca = commit --amend
cam = commit -am
changes = diff --name-status -r
cm = commit --message
co = checkout
cpc = cherry-pick
cu = !git branch --merged | egrep -v \"(^\\*|master|main|develop)\" | xargs git branch -d
d = diff
dc = diff --cached
div = divergence
ds = diff --staged
fu = fetch upstream
mud = merge upstream/develop
h = help
ignored = !git ls-files -v | grep "^[[:lower:]]" | cut -c3-
irb = rebase --interactive
l = log --oneline --decorate
latest-tag = "!git describe --tags `git rev-list --tags --max-count=1`"
lg = log --graph --pretty=format:'%Cred%h%Creset %an -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit --date=relative
ls-ignored = ls-files --exclude-standard --ignored --others
m = merge
mc = merge --continue
mm = merge --no-ff
msg = commit --allow-empty -m
p = cherry-pick -s
pick = cherry-pick
po = push origin
pom = push origin master
pofm = push origin HEAD:refs/for/master
pofd = push origin HEAD:refs/for/develop
pod = push origin develop
prune-remotes = "!for remote in `git remote`; do git remote prune $remote; done"
push = push --tags
r = remote
ra = !git log --graph --abbrev-commit --date=relative -20 --all --pretty='format:%C(yellow)%h%Creset -%C(red)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset'
rb = rebase
rba = rebase --abort
rbc = rebase --continue
rbs = rebase --skip
rh = reset --hard
ru = remote update --prune
s = status --short --branch
sl = shortlog
sm = submodule
sma = submodule add
smu = submodule update --init
st = stash
stl = stash list
stp = stash pop
tagcommit = !sh -c 'git rev-list $0 | head -n 1'
tree = log --graph --pretty=oneline --decorate
undo = reset --soft HEAD^
unwatch = update-index --assume-unchanged
up = pull --rebase --autostash
watch = update-index --no-assume-unchanged
wd = diff --color-words
wds = diff --color-words --staged
[color]
branch = auto
diff = auto
status = auto
interactive = auto
ui = true
pager = true
[color "branch"]
current = yellow reverse
local = yellow
remote = green
[color "diff"]
meta = yellow bold
frag = magenta bold
old = red bold
new = green bold
[color "status"]
added = yellow
changed = green
untracked = cyan
[help]
autocorrect = 0
[apply]
whitespace = nowarn
[merge]
tool = diffmerge
[mergetool "diffmerge"]
cmd = diffmerge --merge --result=\"$MERGED\" \"$LOCAL\" \"$BASE\" \"$REMOTE\"
trustexitcode = false
[mergetool]
keepBackup = false
[push]
default = current
[diff]
tool = diffmerge
renames = copies
mnemonicprefix = true
[difftool]
prompt = false
[difftool "diffmerge"]
cmd = diffmerge \"$LOCAL\" \"$REMOTE\"
[core]
editor = code --wait
excludesfile = /Users/donnfelker/.gitignore_global
autocrlf = input
[filter "media"]
clean = git media clean %f
smudge = git media smudge %f
required = true
[filter "lfs"]
clean = git-lfs clean %f
smudge = git-lfs smudge %f
required = true
[difftool "sourcetree"]
cmd = opendiff \"$LOCAL\" \"$REMOTE\"
path =
[mergetool "sourcetree"]
cmd = /Applications/SourceTree.app/Contents/Resources/opendiff-w.sh \"$LOCAL\" \"$REMOTE\" -ancestor \"$BASE\" -merge \"$MERGED\"
trustExitCode = true
# Hat tip to Kaushik Gopal for some of this
# Prereqs:
# Install:
# VS Code Installed
# Git installed
# brew install git
# Install starship
# brew install starship
# SDKMan: curl -s "https://get.sdkman.io" | bash
# brew install zsh-syntax-highlighting
# brew install zsh-autosuggestions
# make zsh tab completion fix capitalization errors for directories and files
# i don't know if this is required anymore
# autoload -Uz compinit && compinit
# 0 -- vanilla completion (abc => abc)
# 1 -- smart case completion (abc => Abc)
# 2 -- word flex completion (abc => A-big-Car)
# 3 -- full flex completion (abc => ABraCadabra)
zstyle ':completion:*' matcher-list '' \
'm:{a-z\-}={A-Z\_}' \
'r:[^[:alpha:]]||[[:alpha:]]=** r:|=* m:{a-z\-}={A-Z\_}' \
'r:|?=** m:{a-z\-}={A-Z\_}'
# required for homebrew on M1s
eval "$(/opt/homebrew/bin/brew shellenv)"
eval "$(starship init zsh)"
# autcomplete customizations
autoload -U compinit
compinit
compdef g=git
# Edit Properties files of zsh, git, gradle
alias zshpro="code ~/.zshrc;. ~/.zshrc"
alias gitconfig="code ~/.gitconfig; ~/.gitconfig"
alias gradleprops="code ~/.gradle/gradle.properties"
alias g="git"
alias o="open ."
alias la="ls -Gla"
alias mv="mv -i" # Cause mv to write a prompt to standard error before moving a file that would overwrite an existing file.
# Restart ADB server
alias adbr="adb kill-server; adb start-server"
# Clean up all squashed and merged branches locally
alias gclean='git checkout -q main && git for-each-ref refs/heads/ "--format=%(refname:short)" | while read branch; do mergeBase=$(git merge-base main $branch) && [[ $(git cherry main $(git commit-tree $(git rev-parse "$branch^{tree}") -p $mergeBase -m _)) == "-"* ]] && git branch -D $branch; done'
androidBuildToolsVersion() {
echo $ANDROID_BUILD_TOOLS_VERSION
}
# list the most recent files in a directory
lsnew()
{
ls -lt ${1+"$@"} | head -20;
}
# open a manpage in Preview, which can be saved to PDF
pman()
{
# Old versions of Mac preview is here: /Applications/Preview.app
man -t "${1}" | open -f -a /System/Applications/Preview.app
}
export EDITOR="code --wait"
export ANDROID_HOME="$HOME/Library/Android/sdk"
export ANDROID_TOOLS=$ANDROID_HOME/tools
export ANDROID_BUILD_TOOLS_VERSION=`ls $ANDROID_HOME/build-tools | sort -r | head -n 1`
PATH="$ANDROID/HOME/tools:$ANDROID_HOME/tools/bin:$ANDROID_HOME/platform-tools:$PATH"
# Add ~/bin to the path for user specific binaries (drop anything into ~/bin to have it accessible)
PATH="$HOME/bin:$PATH"
#THIS MUST BE AT THE END OF THE FILE FOR SDKMAN TO WORK!!!
export SDKMAN_DIR="$HOME/.sdkman"
[[ -s "$HOME/.sdkman/bin/sdkman-init.sh" ]] && source "$HOME/.sdkman/bin/sdkman-init.sh"
# has to be at the very end
source /opt/homebrew/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
source /opt/homebrew/share/zsh-autosuggestions/zsh-autosuggestions.zsh
# Add RVM to PATH for scripting. Make sure this is the last PATH variable change.
export PATH="$PATH:$HOME/.rvm/bin"
set -g theme_nerd_fonts yes
set -g theme_display_git_stashed_verbose yes
set -g theme_display_git_master_branch yes
set -g theme_display_git_untracked yes
set -g theme_display_git_dirty yes
set -g theme_display_virtualenv yes
set -Ux EDITOR code --wait
rvm default
nvm use 14.15
test -e {$HOME}/.iterm2_shell_integration.fish ; and source {$HOME}/.iterm2_shell_integration.fish ; or true
set -U fish_user_paths /usr/local/bin $fish_user_paths
function fishconfig
code ~/.config/fish/config.fish
end
function g
git $argv
end
function gitconf
code ~/.gitconfig
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment