Skip to content

Instantly share code, notes, and snippets.

@chino

chino/.gitconfig Secret

Last active November 23, 2022 21:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chino/82a36bd269cf602bf4ef to your computer and use it in GitHub Desktop.
Save chino/82a36bd269cf602bf4ef to your computer and use it in GitHub Desktop.
My current ~/.gitconfig
[user]
email = mr.danielaquino@gmail.com
name = Daniel Aquino
# global exclude file of your own
[core]
excludesfile = ~/.git.ignore.global.ini
hooksPath = ~/.git.hooks.global
pager = "diff-so-fancy | less --tabs=2 -RFX --mouse --wheel-lines 3"
whitespace = trailing-space,space-before-tab
[init]
defaultBranch = main
# give nice color output
[color]
ui = auto
diff = auto
status = auto
branch = auto
[color "branch"]
current = yellow reverse
local = yellow
remote = green
[color "status"]
added = green
changed = yellow
untracked = red
[color "diff-highlight"]
oldNormal = red bold
oldHighlight = red bold 52
newNormal = green bold
newHighlight = green bold 22
[color "diff"]
meta = yellow bold
commit = green bold
frag = magenta bold
old = red bold
new = green bold
whitespace = red reverse
# aliases for commands
[alias]
# common aliases
st = status
di = diff
co = checkout
br = branch
sta = stash
# verbose commit messages show your diff in the editor while you write the message..
ci = commit -v
# I never git-merge from upstream so I use this alias to rebase
update = pull --rebase
up = !git update
# nice looking abbreviated and colorized git log
lg = log --graph --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) - %C(bold blue)<%an>%C(reset)%C(bold yellow)%d%C(reset)' --abbrev-commit --date=relative
lga = !"git lg --all"
# helper
whobrokeit = !sh -c \"git log --pretty=format:%an $1..$2 | sort | uniq\" # `git whobrokeit`: List all commit authors between $1 and $2, i.e. "last good state" and "bad state"; one of them broke it.
# gem install gist for gist command line tool
[gist]
private = yes
extension = txt
browse = no
# so you don't have to type this
[push]
default = current
[merge]
# never allow a merge to fast forward you
ff = false
# adds branch description to the merge message
branchdesc = true
# helps to automatically apply fixes to a merge conflict
# it learns the fix you apply to a conflict and auto fixes the next occurrence of it
[rerere]
enabled = true
[rebase]
# allow you to easily use --fixup= commands to the commit message
# then when you go into `git rebase` the fixup commands will automatically take affect
# for instance you can say that this commit should squash/fixup with 2 commits ago
autosquash = true
autostash = true
# better diff / patches
# https://github.com/blog/2188-git-2-9-has-been-released
[diff]
compactionHeuristic = true
[interactive]
diffFilter = diff-so-fancy --patch
[add "interactive"]
useBuiltin = false
*~
*.class
.classpath
*#*#
*.project
*.externalToolBuilders
.*.swp
.directory
.springBeans
.metadata
.DS_Store
# ~/.bash_profile git related parts
# tell other programs what my default editor is
export VISUAL=vim EDITOR=vim
# git shortcuts
alias g="git"
alias gu="git pull --rebase --prune"
alias gi="git commit --verbose"
alias go="git checkout"
alias gd="git diff"
alias gdu="git diff @{u}.."
alias gdw="git diff --word-diff"
alias gdc="git diff --cached"
alias gdcw="git diff --cached --word-diff"
alias gs="git status"
alias gsh="git show"
alias gshu="git show @{u}.."
alias gp="git push"
alias gpo="git push origin"
alias gco="git checkout"
alias gb="git branch"
alias ga="git add"
alias gm="git merge"
alias gap="git add -p"
alias grc="git rebase --continue"
alias gl="git lg"
alias gla="git lg --all"
alias glu="git lg @{u}.."
alias glur="git lg ..@{u}"
alias glm="git lg master.."
alias gg="git grep --color"
function gob
{
local target=$1
git branch | grep -w "$target" ||
git branch --remote | grep -w "/$target" &&
echo "branch of that name already exists..." >&2 &&
return 1
git checkout -b "$target" -t
}
# return the last branch we were on
function glb { git reflog | grep "checkout: moving from" | head -1 | awk '{print $(NF-2)}'; }
# go to the last branch we were on
function gol { go $(glb); }
# go to master (or given branch), update it, go back to last branch, rebase it
function grb { go ${1:-master}; gu; gol; git rebase -i ${1:-master}; }
# name only version
function glmn { gl master.. --name-only "$@"; }
# get the closest fork branch that we cna find
function git_nearest_fork_point { git branch | grep -vF '*' | { while read -r branch; do point=$(git merge-base --fork-point $branch); [[ $point ]] || { [[ $DEBUG == true ]] && echo "$branch has no shared merge-point with HEAD"; continue; }; distance=$(git log $point..HEAD | wc -l); [[ $DEBUG == true ]] && echo $branch merges with HEAD at $point with a distance of $distance >&2; [[ $distance < ${shortest_dist:=9999} ]] && shortest=$branch; done; echo ${shortest:-}; }; }
# show log between closest fork point and current HEAD
function glf { local fork=$(git_nearest_fork_point); [[ $fork ]] || { echo "No fork-point found for HEAD" >&2; return 1; }; gl $fork.. "$@"; }
# git rebase against closest fork point
gr-fork-point(){ local fork=$(git_nearest_fork_point); [[ $fork ]] || { echo "No fork-point found for HEAD" >&2; return 1; }; git rebase -i $fork; };
#####
##### Need to add to gist
#####
function gb-cleanup
{
local target=$1 base=${2:-master}
go $target
grb $base
local diff=$(git diff $base..$target)
[[ $diff ]] && echo "$diff" && return
go $base
echo "No diff between $base..$target found"
echo "Deleting branch: $target"
gb -D $target
echo "Remaining branches:"
gb
}
complete -o bashdefault -o default -o nospace -F __my_git_aliases gb-cleanup
#
# git completion for aliases
#
function __debug_completion_words {
echo "----------" >&2
echo "CWORD = $COMP_CWORD" >&2
echo "WORDS = ${COMP_WORDS[@]}" >&2
echo "LINE = $COMP_LINE" >&2
echo "----------" >&2
}
function __my_git_aliases {
case ${COMP_WORDS[0]} in
gb-cleanup)
export COMP_LINE="git branch ${LINE/gb-cleanup}"
unset COMP_WORDS[0]
export COMP_WORDS=(git branch "${COMP_WORDS[@]}")
let 'COMP_CWORD++'
;;
gb)
export COMP_LINE="git branch ${LINE/gb}"
unset COMP_WORDS[0]
export COMP_WORDS=(git branch "${COMP_WORDS[@]}")
let 'COMP_CWORD++'
;;
go)
export COMP_LINE="git checkout ${LINE/go}"
unset COMP_WORDS[0]
export COMP_WORDS=(git checkout "${COMP_WORDS[@]}")
let 'COMP_CWORD++'
;;
gob)
export COMP_LINE="git checkout ${LINE/go}"
unset COMP_WORDS[0]
export COMP_WORDS=(git checkout "${COMP_WORDS[@]}")
let 'COMP_CWORD++'
;;
esac
__git_wrap__git_main "$@"
}
#complete -o bashdefault -o default -o nospace -F __my_git_aliases git
complete -o bashdefault -o default -o nospace -F __my_git_aliases go
complete -o bashdefault -o default -o nospace -F __my_git_aliases gob
complete -o bashdefault -o default -o nospace -F __my_git_aliases gb
# Note that this not only allows you to amend the last commit message
# if you stage some changes you can actually amend those changes into the previous commit too!
alias gia='git ci --amend'
#
# This is a simple rebase wrapper that first stashes all your uncommitted work
# otherwise rebase will refuse to run if your working tree is dirty!
#
# Note that if you use `edit` in rebase the `stash pop` will invoke! In which case
# I generally just stash it again my self but it can be slightly annoying and/or
# dangerous if you forget..
#
function gr
{
git stash --include-untracked |
grep -q "No local changes to save"; local changes=$?
git rebase -i "$@"
[[ $changes != 0 ]] && git stash pop
}
#
# Another rebase wrapper but this one works slightly differently.
#
# Note: It will stash away everything except for "staged changes" (--keep-index) which is
# the reverse of what stash normally does!
#
# This is useful if your not sure which commit you want to fixup with an autosquash
# so instead you can stage some changes and run this to jump into an interactive git-rebase!
#
# It will commit your staged changes with the fixup message below so you can easily just move
# it to whatever commit you want to fixup!
#
function grf
{
git stash --include-untracked --keep-index # keeps your staged changes around
# need to add back ability to grep last commit message out so autosquash works
word=$(git show --pretty=format:%s | head -n 1 | cut -d\ -f 1)
git ci -m "fixup! $word" # commits them
git rebase -i --autosquash # put the commit where you want
git stash pop # pull back in your working tree
}
# import homebrew man pages on osx
export MANPATH="$(man -w)"
export MANPATH="/usr/local/opt/coreutils/libexec/gnuman:$MANPATH"
export MANPATH="$(
find /usr/local -type d -name man 2>/dev/null |
while read -r path; do
echo -n "$path:"
done
)$MANPATH"
# Note: this isn't needed anymore if your using vimpager
# colors in man pages and less pager
export LESS_TERMCAP_mb=$'\E[01;31m' # begin blinking
export LESS_TERMCAP_md=$'\E[01;38;5;74m' # begin bold
export LESS_TERMCAP_me=$'\E[0m' # end mode
export LESS_TERMCAP_se=$'\E[0m' # end standout-mode
export LESS_TERMCAP_so=$'\E[01;38;35;246m' # begin standout-mode - info box
export LESS_TERMCAP_ue=$'\E[0m' # end underline
export LESS_TERMCAP_us=$'\E[04;38;5;146m' # begin underline
# bash completion scripts
source $(brew --prefix)/etc/bash_completion
#
# BASH PROMPT
#
# shell escape sequences for colors
# wrapped in [] to use in PROMPT_COMMAND
function ps1_color { echo "\[\e[${1}m\]"; }
RESET=$(ps1_color 0)
RED=$(ps1_color 31)
GREEN=$(ps1_color 32)
YELLOW=$(ps1_color 33)
BLUE=$(ps1_color 34); LIGHT_BLUE=$(ps1_color 1\;34)
PURPLE=$(ps1_color 35); LIGHT_PURPLE=$(ps1_color 1\;35)
CYAN=$(ps1_color 36); LIGHT_CYAN=$(ps1_color 1\;36)
GRAY=$(ps1_color 37)
# this is already done by brew automatically?
# $(brew --prefix)/etc/bash_completition.d/git-prompt.sh
export GIT_PS1_SHOWDIRTYSTATE=true # show if your tree is dirty
export GIT_PS1_SHOWSTASHSTATE=true # show if you have something stashed
export GIT_PS1_SHOWUNTRACKEDFILES=true # show if you have untracked files
#export GIT_PS1_SHOWUPSTREAM=verbose\ name # show upstream information
export GIT_PS1_DESCRIBE_STYLE=default # info on detached head state
export GIT_PS1_SHOWCOLORHINTS=true # use color hints
# ~/.vim/bundle/syntastic (no-proxy) [chef:production] (master) [255] $
# also protects against long git-prompt runs
function PROMPT_COMMAND
{
local last_command_rv=$?
# don't let `set -x` print prompt command work
local set_x=$( [[ $- = *x* ]] && echo true || echo false )
set +x
# print exit status of the last command
local last_command_info=$(
[[ $last_command_rv != 0 ]] &&
echo -en " ${RED}[$last_command_rv]${RESET}"
)
# print which chef server we're pointed at
local chefvm_info=$(
[[ $PWD =~ $HOME/repos/chef ]] &&
echo -en " ${YELLOW}[chef:$(chefvm current)]${RESET}"
)
# is this shell configured for the proxy?
local proxy_info=$(
[[ $http_proxy ]] ||
echo -en " ${RED}(no-proxy)${RESET}"
)
# first part of the prompt
local cwd="${CYAN}\w${RESET}"
# __git_ps1 takes these two and inserts the git-info in between
local left_side_prompt="${cwd}${proxy_info}${chefvm_info}"
local right_side_prompt="${last_command_info} \$ "
# there is a big security reason why this must set PS1 it self using variable names
# otherwise a crafted branch name could execute code on your system!
# because of this we can't really capture the output in anyway since it would be vulnerable
# hence this crazy trick is used to let us set a timeout on git execution
# this protects against really large git folders taking forever at every prompt
PATH="~/.tmp:$PATH" \
__git_ps1 "$left_side_prompt" "$right_side_prompt"
# restore `set -x`
$set_x && set -x
}
PROMPT_COMMAND='PROMPT_COMMAND'
# create the helper git wrapper used above
[[ -d ~/.tmp ]] || mkdir ~/.tmp
echo '
timeout 0.1 git "$@"
rv=$?
[[ $rv == 124 && $DEBUG_GIT_PROMPT ]] &&
echo "timed out: git $@" >&2
exit $rv
' > ~/.tmp/git
chmod +x ~/.tmp/git

You should enable the default .git/hooks/pre-commit as this will catch common white space errors.

At this point you can add it to your global hooksPath config too.

Default ssh key

Host github.com
	HostName github.com
	# this would be your github user (can be useful)
	User chino
	# optionally if you dont' want to use your default key
	IdentityFile ~/.ssh/id_rsa.github

Working with github and multiple accounts

http://net.tutsplus.com/tutorials/tools-and-tips/how-to-work-with-github-and-multiple-accounts/

Host github-COMPANY
	HostName github.com
	User git
	IdentityFile ~/.ssh/id_rsa_COMPANY

Now since github uses ssh you can use that ssh alias above when you create a new repo:

git remote add origin git@github-COMPANY:Company/testing.git

Or when you clone a new repo git clone git@github-COMPANY:Company/testing.git

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment