sh/shell/alias/git.sh
2024-11-17 14:03:22 +01:00

513 lines
6.6 KiB
Bash

# add to index
git_add() {
git \
add \
"${@}"
}
ga() { git_add "${@}"; }
# add all to index
git_add_all() {
git \
add \
--all \
"${@}"
}
gaa() { git_add_all "${@}"; }
# add parts of all to index
git_add_all_patch() {
git \
add \
--all \
--patch \
"${@}"
}
gaap() { git_add_all_patch "${@}"; }
# add parts to index
git_add_patch() {
git \
add \
--patch \
"${@}"
}
gap() { git_add_patch "${@}"; }
# create a branch
git_branch() {
git \
branch \
"${@}"
}
gb() { git_branch "${@}"; }
# delete a branch
git_branch_delete() {
git \
branch \
--delete \
"${@}"
}
gbd() { git_branch_delete "${@}"; }
# force a branch deletion
git_branch_delete_force() {
git \
branch \
--delete \
--force \
"${@}"
}
gbdf() { git_branch_delete_force "${@}"; }
# list branches
git_branch_list() {
git \
branch \
--all \
--list \
--verbose \
--verbose \
"${@}"
}
gbl() { git_branch_list "${@}"; }
# set the link to a remote branch from a local branch
git_branch_set_upstream() {
git \
branch \
--set-upstream-to \
"${@}"
}
gbsu() { git_branch_set_upstream "${@}"; }
# redo the last commit with a different message
git_commit_amend_message() {
git \
commit \
--amend \
--message \
"${@}"
}
gcam() { git_commit_amend_message "${@}"; }
# make a root commit
git_commit_empty_message() {
git \
commit \
--allow-empty \
--allow-empty-message \
--message \
"${@}"
}
gcem() { git_commit_empty_message "${@}"; }
# clean untracked files
git_clean_force() {
git \
clean \
-d \
--force \
"${@}"
}
gcf() { git_clean_force "${@}"; }
# commit the index
git_commit_message() {
git \
commit \
--message \
"${@}"
}
gcm() { git_commit_message "${@}"; }
# switch to a branch or checkout file(s) from a commit
git_checkout() {
git \
checkout \
"${@}"
}
gc() { git_checkout "${@}"; }
# checkout an orphan branch
git_checkout_orphan() {
git \
checkout \
--orphan \
"${@}"
}
gco() { git_checkout_orphan "${@}"; }
# pick a commit
git_cherry_pick() {
git \
cherry-pick \
"${@}"
}
gcp() { git_cherry_pick "${@}"; }
# abort the commit pick
git_cherry_pick_abort() {
git \
cherry-pick \
--abort \
"${@}"
}
gcpa() { git_cherry_pick_abort "${@}"; }
# continue the commit pick
git_cherry_pick_continue() {
git \
cherry-pick \
--continue \
"${@}"
}
gcpc() { git_cherry_pick_continue "${@}"; }
# configure the user email
git_config_user_email() {
git \
config \
"user.email" \
"${@}"
}
gcue() { git_config_user_email "${@}"; }
# configure the user name
git_config_user_name() {
git \
config \
"user.name" \
"${@}"
}
gcun() { git_config_user_name "${@}"; }
# differences from last or between commits
git_diff() {
git \
diff \
"${@}"
}
gd() { git_diff "${@}"; }
# display what is indexed in cache
git_diff_cached() {
git \
diff \
--cached \
"${@}"
}
gdc() { git_diff_cached "${@}"; }
# indexed character-level differences
git_diff_cached_word() {
git \
diff \
--cached \
--word-diff-regex "." \
"${@}"
}
gdcw() { git_diff_cached_word "${@}"; }
# differences via external tool
git_diff_tool() {
git \
difftool \
--dir-diff \
"${@}"
}
gdt() { git_diff_tool "${@}"; }
# character-level differences
git_diff_word() {
git \
diff \
--word-diff-regex "." \
"${@}"
}
gdw() { git_diff_word "${@}"; }
# fetch from the remote repository
git_fetch() {
git \
fetch \
--tags \
--verbose \
"${@}"
}
gf() { git_fetch "${@}"; }
# fetch from remote repository and prune local orphan branches
git_fetch_prune() {
gf \
--prune \
"${@}"
}
gfp() { git_fetch_prune "${@}"; }
# garbage collect all orphan commits
git_garbage_collect() {
git \
reflog \
expire \
--all \
--expire "all" &&
git \
gc \
--aggressive \
--prune="now"
}
ggc() { git_garbage_collect "${@}"; }
# initialize a new repository
git_init() {
git \
init \
"${@}"
}
gi() { git_init "${@}"; }
# initialize a new bare repository
git_init_bare() {
git \
init \
--bare \
"${@}"
}
gib() { git_init_bare "${@}"; }
# log history
git_log() {
local format="\
%C(auto)%h%d
S %C(red)%GS
A %C(green)%ai
%C(green)%an %ae
C %C(blue)%ci
%C(blue)%cn %ce
%B"
git \
log \
--abbrev=8 \
--abbrev-commit \
--format="${format}" \
--graph \
"${@}"
}
gl() { git_log "${@}"; }
# log all history
git_log_all() {
gl \
--all \
"${@}"
}
gla() { git_log_all "${@}"; }
# log all history with patches
git_log_all_patch() {
gl \
--all \
--patch \
"${@}"
}
glap() { git_log_all_patch "${@}"; }
# log history with patches
git_log_patch() {
gl \
--patch \
"${@}"
}
glp() { git_log_patch "${@}"; }
# fast-forward merge to remote branch
git_merge() {
git \
merge \
--ff-only \
"${@}"
}
gm() { git_merge "${@}"; }
# abort the current merge commit
git_merge_abort() {
git \
merge \
--abort \
"${@}"
}
gma() { git_merge_abort "${@}"; }
# do a merge commit
git_merge_commit() {
git \
merge \
--no-ff \
--message \
"${@}"
}
gmc() { git_merge_commit "${@}"; }
# squash a branch and index its modifications
gms() {
git \
merge \
--squash \
"${@}"
}
# merge via external tool
gmt() {
git \
mergetool \
"${@}"
}
# push to the remote repository
gp() {
git \
push \
--tags \
--verbose \
"${@}"
}
# delete from the remote repository
gpd() {
git \
push \
--delete \
"${@}"
}
# force the push to the remote repository
gpf() {
gp \
--force \
"${@}"
}
# rebase current branch onto another
grb() {
git \
rebase \
"${@}"
}
# abort current rebase
grba() {
git \
rebase \
--abort \
"${@}"
}
# continue current rebase
grbc() {
git \
rebase \
--continue \
"${@}"
}
# force rebase without fast-forward
grbf() {
git \
rebase \
--force-rebase \
"${@}"
}
# rebase interactively
grbi() {
git \
rebase \
--interactive \
"${@}"
}
# remove and add removal to index
grm() {
git \
rm \
"${@}"
}
# add a new remote repository
grma() {
git \
remote \
add \
"${@}"
}
# list remote repositories
grml() {
git \
remote \
--verbose \
"${@}"
}
# show connection to a remote repository
grms() {
git \
remote \
show \
"${@}"
}
# set the location of a remote repository
grmsu() {
git \
remote \
set-url \
"${@}"
}
# remove file(s) from index or move current branch pointer
grs() {
git \
reset \
"${@}"
}
# wipe modifications or reset current branch to another commit
grsh() {
git \
reset \
--hard \
"${@}"
}
# current state of repository
gs() {
git \
status \
--untracked-files="all" \
"${@}"
}
# show a commit
gsc() {
git \
show \
"${@}"
}
# tag a commit
gt() {
git \
tag \
"${@}"
}
# delete a tag
gtd() {
git \
tag \
--delete \
"${@}"
}