Skip to content

Instantly share code, notes, and snippets.

@jfcherng
Last active April 13, 2024 17:57
Show Gist options
  • Save jfcherng/1c1aab8cdf625a22f8429cdc46e5f0a5 to your computer and use it in GitHub Desktop.
Save jfcherng/1c1aab8cdf625a22f8429cdc46e5f0a5 to your computer and use it in GitHub Desktop.
一些關於 GIT 的設定

Prerequisites

Git Installation

Ubuntu

sudo add-apt-repository -y ppa:git-core/ppa
sudo apt update
sudo apt install -y git pandoc catdoc odt2txt

CentOS 7

yum install http://opensource.wandisco.com/centos/7/git/x86_64/wandisco-git-release-7-2.noarch.rpm
yum install git

Manually Compilation

https://github.com/jfcherng/my-scripts/blob/master/general/git/compile_git.sh

SSH Key Generation

ssh-keygen -t ed25519

Let "g" trigger git-completion

Just because I alias g to git on my machine.

complete -o bashdefault -o default -o nospace -F __git_wrap__git_main g

Setup

git config --global --replace-all safe.directory "*" # as of git 2.35.3
git config --global absorb.maxStack 50
git config --global alias.a "add"
git config --global alias.abs "absorb"
git config --global alias.bl "blame"
git config --global alias.br "branch -vv"
git config --global alias.chp "cherry-pick"
git config --global alias.ci "commit -s"
git config --global alias.cl "clean"
git config --global alias.co "checkout"
git config --global alias.contributors "shortlog --summary --numbered"
git config --global alias.d "diff --patch-with-stat"
git config --global alias.dt "difftool"
git config --global alias.exec '!exec ' # execute command at git root
git config --global alias.fp "format-patch"
git config --global alias.ft "fetch --tags --force --prune"
git config --global alias.grp "grep -n --color -E"
git config --global alias.gone "! f() { git fetch --all --prune --prune-tags; git branch -vv | awk '/: gone]/{print substr(\$0,2)}' | awk '{print \$1}' | xargs git branch -D; }; f"
git config --global alias.l "log --graph --date=short --color --pretty=format:'%C(yellow bold)%h%C(auto)%d%Creset - %s %C(green bold)[%an]%Creset %C(blue bold)(%ad, %cr)%Creset'"
git config --global alias.lg "log --graph --date=short --color --pretty=format:'%C(yellow bold)%h%Creset %G?%C(auto)%d%Creset - %s %C(green bold)[%an]%Creset %C(blue bold)(%ad, %cr)%Creset'"
git config --global alias.m "merge"
git config --global alias.mt "mergetool"
git config --global alias.pl "pull --tags --prune"
git config --global alias.rb "rebase"
git config --global alias.root "rev-parse --show-toplevel"
git config --global alias.rs "reset"
git config --global alias.sh "show --patch-with-stat --pretty=fuller --show-signature"
git config --global alias.shrink "! git worktree prune && git reflog expire --expire=now --all && git gc --aggressive --prune=now"
git config --global alias.sm "submodule"
git config --global alias.st "status --show-stash"
git config --global alias.sync "! git fetch --tags --force --prune --all && git reset --hard @{upstream}"
git config --global alias.syncm "! git sync && git submodule update --init --force"
git config --global alias.syncmr "! git sync && git submodule update --init --force --recursive"
git config --global alias.wt "worktree"
git config --global color.diff-highlight.newHighlight "green bold 22"
git config --global color.diff-highlight.newNormal "green bold"
git config --global color.diff-highlight.oldHighlight "red bold 52"
git config --global color.diff-highlight.oldNormal "red bold"
git config --global color.diff.commit "227 bold"
git config --global color.diff.frag "magenta bold"
git config --global color.diff.meta "227"
git config --global color.diff.new "green bold"
git config --global color.diff.old "red bold"
git config --global color.diff.whitespace "red reverse"
git config --global color.ui "auto"
git config --global commit.template "~/.git-commit-template" && touch ~/.git-commit-template
git config --global core.attributesfile "~/.gitattributes"
git config --global core.autocrlf "input"
git config --global core.editor "vim"
git config --global core.filemode true
git config --global core.ignorecase false
git config --global core.quotepath false
git config --global core.safecrlf false
git config --global diff.algorithm "histogram"
git config --global diff.colorMoved "default"
git config --global difftool.prompt false
git config --global gui.encoding "utf-8"
git config --global i18n.commitencoding "utf-8"
git config --global init.defaultBranch "main"
git config --global lfs.batch false
git config --global log.date iso-local
git config --global mergetool.keepBackup false
git config --global mergetool.prompt false
git config --global pull.autostash true
git config --global pull.rebase true
git config --global push.default "simple"
git config --global rebase.autostash true
git config --global rebase.autosquash true
git config --global rebase.updateRefs true # https://github.blog/2022-10-03-highlights-from-git-2-38/#rebase-dependent-branches-with-update-refs
git config --global rerere.enabled true

Setup (Optional)

# personal information
git config --global user.email "jfcherng@gmail.com"
git config --global user.name "Jack Cherng"

# auto sign with GPG key? See following links:
# - http://irtfweb.ifa.hawaii.edu/~lockhart/gpg/
# - http://pre.tir.tw/008/blog/output/gnupg-gpg-jin-yao-guan-li.html
# - https://www.gnupg.org/gph/en/manual/x334.html
# the key ID can be viewed by "$ gpg --show-keys pubring.gpg"
git config --global user.signingkey A5AC4BCD2D88BAAF6A1D73F11314F81CA2D39ECE # this is my key ID
git config --global commit.gpgsign true

# is "delta" installed? ( https://github.com/dandavison/delta )
git config --global core.pager "delta"
git config --global delta.line-numbers true
git config --global interactive.diffFilter "delta --color-only"

# merge tools are installed?
# I use Beyond Compare
git config --global diff.tool bc
git config --global merge.tool bc
# I use Sublime Merge
git config --global diff.tool sm
git config --global merge.tool sm
git config --global mergetool.sm.trustExitCode true

# tools for Linux (just copy and set all)
git config --global difftool.bc.path "bcompare"
git config --global mergetool.bc.path "bcompare"
git config --global difftool.sm.cmd 'sublime_merge "$BASE" "$LOCAL" "$REMOTE"'
git config --global mergetool.sm.cmd 'sublime_merge --wait mergetool "$BASE" "$LOCAL" "$REMOTE" -o "$MERGED"'

# tools for Windows (just copy and set all)
git config --global difftool.bc.path "bcomp.exe"
git config --global mergetool.bc.path "bcomp.exe"
git config --global difftool.sm.cmd 'smerge.exe "$BASE" "$LOCAL" "$REMOTE"'
git config --global mergetool.sm.cmd 'smerge.exe --wait mergetool "$BASE" "$LOCAL" "$REMOTE" -o "$MERGED"'

# diff filters
# http://www.wagner.pp.ru/~vitus/software/catdoc/
# https://www-uxsup.csx.cam.ac.uk/pub/windows/cygwin/x86/release/odt2txt/
# http://ebstudio.info/home/xdoc2txt.html
git config --global diff.catdoc.textconv "catdoc"
git config --global diff.catppt.textconv "catppt"
git config --global diff.xls2txt.textconv "xls2txt"
git config --global diff.odt2txt.textconv "odt2txt"
git config --global diff.xdoc2txt.textconv "xdoc2txt -8"
git config --global diff.pandoc.textconv "pandoc --to=markdown"

.gitattributes

*.doc diff=doc
*.xls diff=xls
*.ppt diff=ppt
*.odt diff=odt
*.docx diff=docx
*.xlsx diff=xlsx
*.pptx diff=pptx
*.pdf diff=pdf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment