Skip to content

Instantly share code, notes, and snippets.

@Hipfox
Last active June 2, 2025 02:35
Show Gist options
  • Save Hipfox/2cf8c46f04c7eedf05ae to your computer and use it in GitHub Desktop.
Save Hipfox/2cf8c46f04c7eedf05ae to your computer and use it in GitHub Desktop.
gitconfig
[user]
name = example
email = [email protected]
[core]
excludesfile = ~/.gitignore
autocrlf = input
editor = vim
[color]
ui = auto
[column]
ui = auto
[branch]
sort = -committerdate
[tag]
sort = version:refname
[init]
defaultBranch = main
[alias]
# 基本版本:在當前目錄初始化 bare repo
init-bare-main = "!f() { \
echo 'Initializing bare repository with main worktree...'; \
git init --bare .bare && \
git --git-dir=.bare remote add origin $(pwd)/.bare && \
git --git-dir=.bare symbolic-ref HEAD refs/heads/main && \
git --git-dir=.bare worktree add main && \
echo 'Done! Use: cd main && git add . && git commit -m \"Initial commit\"'; \
}; f"
# Drupal 模組版本:在當前目錄初始化並建立模組檔案
init-drupal-module = "!f() { \
MODULE_NAME=\"${1:-$(basename $(pwd))}\"; \
echo \"Initializing Drupal module: $MODULE_NAME\"; \
git init --bare .bare && \
git --git-dir=.bare remote add origin $(pwd)/.bare && \
git --git-dir=.bare symbolic-ref HEAD refs/heads/main && \
git --git-dir=.bare worktree add main && \
cd main && \
echo \"name: $MODULE_NAME\" > ${MODULE_NAME}.info.yml && \
echo \"type: module\" >> ${MODULE_NAME}.info.yml && \
echo \"core_version_requirement: ^10 || ^11\" >> ${MODULE_NAME}.info.yml && \
echo \"description: 'Custom $MODULE_NAME module'\" >> ${MODULE_NAME}.info.yml && \
echo \"<?php\" > ${MODULE_NAME}.module && \
echo \"\" >> ${MODULE_NAME}.module && \
echo \"/**\" >> ${MODULE_NAME}.module && \
echo \" * @file\" >> ${MODULE_NAME}.module && \
echo \" * $MODULE_NAME module.\" >> ${MODULE_NAME}.module && \
echo \" */\" >> ${MODULE_NAME}.module && \
mkdir -p src && \
echo \"# $MODULE_NAME\" > README.md && \
git add . && \
git commit -m 'Initial Drupal module structure' && \
cd .. && \
echo \"Module '$MODULE_NAME' initialized in main/ directory\"; \
}; f"
fix-bare = !git config remote.origin.fetch '+refs/heads/*:refs/remotes/origin/*' && git fetch && git for-each-ref --format='%(refname:short)' refs/heads | xargs -I{} git branch --set-upstream-to=origin/{}
setup-bare = !echo 'gitdir: ./.bare' > .git && git fix-bare
wta = "!wta_git_worktree_add() { \
branch_name=\"$1\"; \
dir_name=$(echo \"$1\" | \
sed 's/\\//-/g' | \
sed 's/[^a-zA-Z0-9-]/_/g' | \
sed 's/__*/_/g' | \
sed 's/^[-_]*//;s/[-_]*$//' | \
sed 's/^$/fallback-dir/'); \
\
if [ -z \"$dir_name\" ] || [ \"$dir_name\" = \".\" ] || [ \"$dir_name\" = \"..\" ]; then \
dir_name=\"worktree-$(date +%Y%m%d-%H%M%S)\"; \
echo \"⚠ Generated safe directory name: $dir_name\"; \
fi; \
\
if [ -d \"$dir_name\" ]; then \
echo \"Directory $dir_name already exists!\"; \
return 1; \
fi; \
echo \"Creating worktree: $dir_name (branch: $branch_name)\"; \
\
if git rev-parse --verify $branch_name >/dev/null 2>&1; then \
echo \"Using existing local branch '$branch_name'...\"; \
git worktree add $dir_name $branch_name && \
echo \"✓ Created worktree '$dir_name' using existing branch '$branch_name'\"; \
elif git rev-parse --verify origin/$branch_name >/dev/null 2>&1; then \
echo \"Found origin/$branch_name, creating tracking branch...\"; \
git worktree add -b $branch_name $dir_name origin/$branch_name && \
echo \"✓ Created branch '$branch_name' tracking origin/$branch_name in directory '$dir_name'\"; \
else \
echo \"Branch '$branch_name' not found, looking for base branch...\"; \
for branch in main master develop trunk; do \
if git rev-parse --verify origin/$branch >/dev/null 2>&1; then \
echo \"Found origin/$branch, creating new branch...\"; \
git worktree add -b $branch_name $dir_name origin/$branch && \
echo \"✓ New branch '$branch_name' based on origin/$branch in directory '$dir_name'\" && break; \
fi; \
done || echo \"✗ No suitable base branch found\"; \
fi; \
}; wta_git_worktree_add"
wtl = worktree list
wtr = "!f() { git worktree remove $1 && echo \"✓ Removed worktree: $1\"; }; f"
br = branch
sw = switch
swc = switch -c
st = status
rema = rebase origin/master master
cm = commit
cmt = commit -v
cma = commit -a -v
co = checkout
m = checkout master
dc = diff --cached
df = diff
d = diff -C
ds = diff -C --stat
dsp = diff -C --stat -p
lg = log --graph --pretty=format:'%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset' --abbrev-commit --decorate --date=short
lga = log --graph --pretty=format:'%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset' --abbrev-commit --all --decorate --date=short
ll = log --graph --pretty=format:'%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset' --abbrev-commit --all --decorate --date=short --since='14 days ago'
lf = log --graph --pretty=format:'%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset' --abbrev-commit --first-parent --decorate --date=short
recent = for-each-ref --sort=-committerdate refs/heads/ --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(color:red)%(objectname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))'
ls = ls-files
alias = !git config --list | grep 'alias\\.' | sed 's/alias\\.\\([^=]*\\)=\\(.*\\)/\\1\\\t => \\2/' | sort
[push]
default = simple
autoSetupRemote = true
followTags = true
[fetch]
prune = true
pruneTags = true
all = true
[merge]
tool = vimdiff
conflictstyle = diff3
# (just 'diff3' if git version < 2.3)
# conflictstyle = zdiff3
# ort = true
[mergetool]
keepBackup = false
[diff]
tool = vimdiff
algorithm = histogram
colorMoved = plain
mnemonicPrefix = true
renames = true
[difftool]
prompt = false
[pull]
rebase = true
[checkout]
defaultRemote = origin
[help]
autocorrect = prompt
[commit]
verbose = true
[rerere]
enabled = true
autoupdate = true
[rebase]
autoSquash = true
autoStash = true
# updateRefs = true # Git 2.38+ 才支援,預設 false
[protocol]
version = 2
[transfer]
fsckobjects = true
[receive]
fsckObjects = true
[safe]
# directory = *
[include]
path = ~/.gitconfig.local
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment