Last active
January 9, 2025 10:28
-
-
Save huaminghuangtw/24b029222e1152ca34138521907c15e3 to your computer and use it in GitHub Desktop.
My Git Configuration. For more Git alias commands please visit: https://github.com/GitAlias/gitalias
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[user] | |
name = Hua-Ming Huang | |
email = [email protected] | |
signingkey = ~/.ssh/id_rsa.pub | |
[github] | |
user = huaminghuangtw | |
tokentype = ssh | |
[commit] | |
gpgSign = true | |
[gpg] | |
format = ssh | |
[include] | |
path = ~/.git-sendemail | |
[core] | |
editor = code --wait | |
ignorecase = false | |
[help] | |
autocorrect = 1 | |
[init] | |
defaultBranch = main | |
[push] | |
default = current | |
autoSetupRemote = true | |
[pull] | |
default = current | |
rebase = true | |
[diff] | |
mnemonicprefix = true | |
ignoreSubmodules = dirty | |
[branch] | |
autosetuprebase = always | |
[apply] | |
# Detect whitespace errors when applying a patch | |
whitespace = fix | |
[submodule] | |
recurse = false | |
[color] | |
ui = true | |
branch = auto | |
diff = auto | |
status = auto | |
[pretty] | |
myformat = format:%C(yellow)%h %Cred%cr %Cblue(%an)%C(cyan)%d%Creset %s | |
# See more examples: https://github.com/GitAlias/gitalias | |
[alias] | |
cfg = config --global --edit | |
# Clone a repository including all submodules | |
c = clone --recursive | |
start = !"git init && git add . && git commit --allow-empty -m 'Initial commit'" | |
save = !"git add --all && git commit -m 'SAVEPOINT'" | |
cm = !"git add . && git commit -m" | |
rao = remote add origin | |
remotes = remote -v | |
st = status -s | |
d = !"git diff-index --quiet HEAD -- || clear; git --no-pager diff --patch-with-stat" | |
ls = ls-files | |
ls-ignored = ls-files --others --i --exclude-standard | |
last = log -1 HEAD --stat --pretty=myformat | |
ol = log --pretty=myformat | |
changelog = log --pretty='- %s' > CHANGELOG.md | |
f = fetch | |
up = !"git checkout main && git pull --rebase --no-recurse-submodules origin main && git submodule-update" | |
pull-force = !"git branch backup && git fetch --all && git reset --hard origin/${1-main}" | |
br = branch -a | |
# Delete local branches | |
br-del-local = branch --delete | |
# Delete remote branches | |
br-del-remote = push origin --delete | |
# Switch to a branch, creating it if doesn't exist | |
goto = "!git switch \"$1\" || git switch -c \"$1\"" | |
p = push | |
pt = push --tags | |
tags = tag -n1 --list | |
stashes = stash list | |
# Modify the latest commit with all current changes and a new commit message | |
amend = commit --amend --all -m | |
cleanup = !"git remote prune origin && git gc && git clean -dfx && git stash clear" | |
# Delete local branches that have been merged into the specified (or default) base branch, and prune remote-tracking branches. | |
cleanup-merged-branches = "!f() { \ | |
local base_branch=${1:-main}; \ | |
git branch --merged \"$base_branch\" | grep -vE \"(^\\*|$base_branch)\" | xargs -r git branch -d; \ | |
git fetch -p; \ | |
}; f" | |
undo = reset HEAD~ --mixed | |
undo-hard = !"git reset --hard HEAD^" | |
# Reset work that you never committed. | |
# Note that you can run the `git reflog` command and find the SHA of the commit, if you realize later that you made a mistake with the reset. | |
# This alias can be used to replace the `git reset HEAD --hard` command. | |
wipe = "!f() { \ | |
rev=$(git rev-parse ${1-HEAD}); \ | |
git add -A && \ | |
git commit --allow-empty -qm 'WIPE SAVEPOINT' && \ | |
git reset $rev --hard; \ | |
}; f" | |
# Run this alias before merge to check for any conflicts | |
merge-test = "!f() { \ | |
if [ -z \"$1\" ]; then \ | |
read -p \"Enter the branch you want to test merge: \" branch; \ | |
else \ | |
branch=\"$1\"; \ | |
fi; \ | |
if ! git diff-index --quiet HEAD --; then \ | |
echo \"You have uncommitted changes. Please commit or stash them before merging.\"; \ | |
return 1; \ | |
fi; \ | |
git merge --no-commit --no-ff \"$branch\" && git merge --abort; \ | |
echo \"Merge aborted.\"; \ | |
git status; \ | |
}; f" | |
ignore-unignored = "!f() { \ | |
echo \"Removing untracked files that were previously ignored...\"; \ | |
git rm -r --cached --ignore-unmatch . && \ | |
git add . && \ | |
git commit -m \".gitignore fix: Remove ignored files\"; \ | |
git update-index --assume-unchanged . && \ | |
git push; \ | |
}; f" | |
unignore-ignored = "!f() { \ | |
git add -f \"$1\" && \ | |
git add . && \ | |
git commit -m '.gitignore fix' && \ | |
git update-index --assume-unchanged \"$1\" && \ | |
git push; \ | |
}; f" | |
# Open the GitHub repository | |
open = "!f() { \ | |
url=$(git remote get-url origin | \ | |
sed -e 's/[email protected]:/https:\\/\\/github.com\\//' -e 's/.git$//'); \ | |
open \"$url\"; \ | |
}; f" | |
# Keep gh-pages up-to-date with the main branch | |
sync-ghpages = !"git checkout gh-pages && git rebase main && git push origin gh-pages && git checkout main" | |
submodule-add="!f() { \ | |
local force_option=; \ | |
if [ "$1" = "--force" ]; then \ | |
force_option="--force"; \ | |
shift; \ | |
fi; \ | |
if [ $# -lt 1 ] || [ $# -gt 2 ]; then \ | |
echo "Usage: git submodule-add [--force] <URL_to_Git_repo_of_submodule> [<path/to/submodule>]" >&2; \ | |
return 1; \ | |
fi; \ | |
git submodule add $force_option "$1" "${2:-}"; \ | |
}; f" | |
submodule-remove="!f() { \ | |
if [ $# -ne 1 ]; then \ | |
echo "Usage: git submodule-remove <path/to/submodule>" >&2; \ | |
return 1; \ | |
fi; \ | |
local path="$1"; \ | |
git submodule deinit -f -- "$path" && \ | |
rm -rf .git/modules/"$path" && \ | |
git rm -f "$path"; \ | |
}; f" | |
submodule-update="!f() { \ | |
git submodule foreach "git pull origin main" && \ | |
git submodule status; \ | |
}; f" | |
submodule-status="!f() { \ | |
git submodule status --recursive; \ | |
}; f" | |
auto-pull = "!f() { \ | |
max_files=10; \ | |
current_time=$(date '+%Y-%m-%d %H:%M:%S'); \ | |
remote_url=$(git config --get remote.origin.url); \ | |
repo_name=$(basename \"$remote_url\" .git); \ | |
affected_files=$(git status --porcelain | awk '{print substr($0, 4)}'); \ | |
affected_files=$(echo \"$affected_files\" | head -n $max_files); \ | |
commit_msg_title=\"Updating <$repo_name> from my MacBook ($current_time)\"; \ | |
commit_msg_description=$(printf \"Affected file(s) (only up to %s files are shown):\\n%s\" \"$max_files\" \"$affected_files\"); \ | |
if [ -n \"$(git status -s)\" ]; then \ | |
git add .; \ | |
git commit -m \"$commit_msg_title\" -m \"$commit_msg_description\"; \ | |
fi; \ | |
git up; \ | |
}; f" | |
auto-push = "!f() { \ | |
max_files=10; \ | |
current_time=$(date '+%Y-%m-%d %H:%M:%S'); \ | |
remote_url=$(git config --get remote.origin.url); \ | |
repo_name=$(basename \"$remote_url\" .git); \ | |
affected_files=$(git status --porcelain | awk '{print substr($0, 4)}'); \ | |
affected_files=$(echo \"$affected_files\" | head -n $max_files); \ | |
commit_msg_title=\"Updating <$repo_name> from my MacBook ($current_time)\"; \ | |
commit_msg_description=$(printf \"Affected file(s) (only up to %s files are shown):\\n%s\" \"$max_files\" \"$affected_files\"); \ | |
if [ -n \"$(git status -s)\" ]; then \ | |
git add .; \ | |
git commit -m \"$commit_msg_title\" -m \"$commit_msg_description\"; \ | |
fi; \ | |
git push origin main; \ | |
}; f" | |
sync = "!git auto-pull && git auto-push" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment