sh/shell/alias/git.sh

536 lines
7.5 KiB
Bash
Raw Normal View History

2024-11-17 16:15:47 +00:00
GIT_LOG_FORMAT="\
%C(auto)%h%d
S %C(red)%GS
2024-11-17 16:24:17 +00:00
A %C(green)%an %ae
%C(green)%ai
C %C(blue)%cn %ce
%C(blue)%ci
2024-11-17 16:15:47 +00:00
%B"
2023-05-09 20:02:34 +00:00
# add to index
2024-11-17 15:59:22 +00:00
ga() { git_add "${@}"; }
2024-11-17 13:03:22 +00:00
git_add() {
2024-11-16 15:59:23 +00:00
git \
add \
"${@}"
}
2023-05-09 20:02:34 +00:00
# add all to index
2024-11-17 15:59:22 +00:00
gaa() { git_add_all "${@}"; }
2024-11-17 13:03:22 +00:00
git_add_all() {
2024-11-16 15:59:23 +00:00
git \
add \
--all \
"${@}"
}
2023-05-09 20:02:34 +00:00
2024-11-16 16:01:12 +00:00
# add parts of all to index
2024-11-17 15:59:22 +00:00
gaap() { git_add_all_patch "${@}"; }
2024-11-17 13:03:22 +00:00
git_add_all_patch() {
2024-11-16 16:01:12 +00:00
git \
add \
--all \
--patch \
"${@}"
}
2023-05-14 20:48:39 +00:00
# add parts to index
2024-11-17 15:59:22 +00:00
gap() { git_add_patch "${@}"; }
2024-11-17 13:03:22 +00:00
git_add_patch() {
2024-11-16 16:01:12 +00:00
git \
add \
--patch \
"${@}"
}
2023-05-14 20:48:39 +00:00
2023-05-09 20:02:34 +00:00
# create a branch
2024-11-17 15:59:22 +00:00
gb() { git_branch "${@}"; }
2024-11-17 13:03:22 +00:00
git_branch() {
2024-11-16 17:43:09 +00:00
git \
branch \
"${@}"
}
2023-05-09 20:02:34 +00:00
# delete a branch
2024-11-17 15:59:22 +00:00
gbd() { git_branch_delete "${@}"; }
2024-11-17 13:03:22 +00:00
git_branch_delete() {
2024-11-16 17:43:09 +00:00
git \
branch \
--delete \
"${@}"
}
2023-05-09 20:02:34 +00:00
# force a branch deletion
2024-11-17 15:59:22 +00:00
gbdf() { git_branch_delete_force "${@}"; }
2024-11-17 13:03:22 +00:00
git_branch_delete_force() {
2024-11-16 17:43:09 +00:00
git \
branch \
--delete \
--force \
"${@}"
}
2023-05-09 20:02:34 +00:00
# list branches
2024-11-17 15:59:22 +00:00
gbl() { git_branch_list "${@}"; }
2024-11-17 13:03:22 +00:00
git_branch_list() {
2024-11-16 17:43:09 +00:00
git \
branch \
--all \
--list \
--verbose \
--verbose \
"${@}"
}
2023-05-09 20:02:34 +00:00
# set the link to a remote branch from a local branch
2024-11-17 15:59:22 +00:00
gbsu() { git_branch_set_upstream "${@}"; }
2024-11-17 12:23:38 +00:00
git_branch_set_upstream() {
2024-11-16 17:43:09 +00:00
git \
branch \
--set-upstream-to \
"${@}"
}
2023-05-09 20:02:34 +00:00
# switch to a branch or checkout file(s) from a commit
2024-11-17 15:59:22 +00:00
gc() { git_checkout "${@}"; }
2024-11-17 12:35:36 +00:00
git_checkout() {
2024-11-16 17:51:33 +00:00
git \
checkout \
"${@}"
}
2023-05-09 20:02:34 +00:00
# checkout an orphan branch
2024-11-17 15:59:22 +00:00
gco() { git_checkout_orphan "${@}"; }
2024-11-17 12:35:36 +00:00
git_checkout_orphan() {
2024-11-16 17:51:33 +00:00
git \
checkout \
--orphan \
"${@}"
}
2023-05-09 20:02:34 +00:00
# pick a commit
2024-11-17 15:59:22 +00:00
gcp() { git_cherry_pick "${@}"; }
2024-11-17 12:35:36 +00:00
git_cherry_pick() {
2024-11-16 17:51:33 +00:00
git \
cherry-pick \
"${@}"
}
2023-05-09 20:02:34 +00:00
# abort the commit pick
2024-11-17 15:59:22 +00:00
gcpa() { git_cherry_pick_abort "${@}"; }
2024-11-17 12:35:36 +00:00
git_cherry_pick_abort() {
2024-11-16 17:51:33 +00:00
git \
cherry-pick \
--abort \
"${@}"
}
2023-05-09 20:02:34 +00:00
# continue the commit pick
2024-11-17 15:59:22 +00:00
gcpc() { git_cherry_pick_continue "${@}"; }
2024-11-17 12:35:36 +00:00
git_cherry_pick_continue() {
2024-11-16 17:51:33 +00:00
git \
cherry-pick \
--continue \
"${@}"
}
2023-05-09 20:02:34 +00:00
2024-11-17 16:05:44 +00:00
# clean untracked files
gcf() { git_clean_force "${@}"; }
git_clean_force() {
git \
clean \
-d \
--force \
"${@}"
}
# redo the last commit with a different message
gcam() { git_commit_amend_message "${@}"; }
git_commit_amend_message() {
git \
commit \
--amend \
--message \
"${@}"
}
# make a root commit
gcem() { git_commit_empty_message "${@}"; }
git_commit_empty_message() {
git \
commit \
--allow-empty \
--allow-empty-message \
--message \
"${@}"
}
# commit the index
gcm() { git_commit_message "${@}"; }
git_commit_message() {
git \
commit \
--message \
"${@}"
}
2023-05-09 20:02:34 +00:00
# configure the user email
2024-11-17 15:59:22 +00:00
gcue() { git_config_user_email "${@}"; }
2024-11-17 12:58:39 +00:00
git_config_user_email() {
2024-11-16 17:54:56 +00:00
git \
config \
"user.email" \
"${@}"
}
# configure the user name
2024-11-17 15:59:22 +00:00
gcun() { git_config_user_name "${@}"; }
2024-11-17 12:58:39 +00:00
git_config_user_name() {
2024-11-16 17:54:56 +00:00
git \
config \
"user.name" \
"${@}"
}
2023-05-09 20:02:34 +00:00
# differences from last or between commits
2024-11-17 15:59:22 +00:00
gd() { git_diff "${@}"; }
2024-11-17 12:58:39 +00:00
git_diff() {
2024-11-16 18:01:27 +00:00
git \
diff \
"${@}"
}
2023-05-09 20:02:34 +00:00
# display what is indexed in cache
2024-11-17 15:59:22 +00:00
gdc() { git_diff_cached "${@}"; }
2024-11-17 12:58:39 +00:00
git_diff_cached() {
2024-11-16 18:01:27 +00:00
git \
diff \
--cached \
"${@}"
}
2023-05-09 20:02:34 +00:00
# indexed character-level differences
2024-11-17 15:59:22 +00:00
gdcw() { git_diff_cached_word "${@}"; }
2024-11-17 12:58:39 +00:00
git_diff_cached_word() {
2024-11-16 18:01:27 +00:00
git \
diff \
--cached \
--word-diff-regex "." \
"${@}"
}
2023-05-09 20:02:34 +00:00
# differences via external tool
2024-11-17 15:59:22 +00:00
gdt() { git_diff_tool "${@}"; }
2024-11-17 12:58:39 +00:00
git_diff_tool() {
2024-11-16 18:01:27 +00:00
git \
difftool \
--dir-diff \
"${@}"
}
2023-05-09 20:02:34 +00:00
# character-level differences
2024-11-17 15:59:22 +00:00
gdw() { git_diff_word "${@}"; }
2024-11-17 12:58:39 +00:00
git_diff_word() {
2024-11-16 18:01:27 +00:00
git \
diff \
--word-diff-regex "." \
"${@}"
}
2023-05-09 20:02:34 +00:00
# fetch from the remote repository
2024-11-17 15:59:22 +00:00
gf() { git_fetch "${@}"; }
2024-11-17 12:58:39 +00:00
git_fetch() {
2024-11-16 18:02:56 +00:00
git \
fetch \
--tags \
--verbose \
"${@}"
}
2023-05-09 20:02:34 +00:00
# fetch from remote repository and prune local orphan branches
2024-11-17 15:59:22 +00:00
gfp() { git_fetch_prune "${@}"; }
2024-11-17 12:58:39 +00:00
git_fetch_prune() {
2024-11-17 16:14:15 +00:00
git_fetch \
2024-11-16 18:02:56 +00:00
--prune \
"${@}"
}
2023-05-09 20:02:34 +00:00
# garbage collect all orphan commits
2024-11-17 15:59:22 +00:00
ggc() { git_garbage_collect "${@}"; }
2024-11-17 12:58:39 +00:00
git_garbage_collect() {
2024-11-16 18:07:11 +00:00
git \
reflog \
expire \
--all \
--expire "all" &&
git \
gc \
--aggressive \
--prune="now"
}
2023-05-09 20:02:34 +00:00
# initialize a new repository
2024-11-17 15:59:22 +00:00
gi() { git_init "${@}"; }
2024-11-17 12:58:39 +00:00
git_init() {
2024-11-16 18:08:27 +00:00
git \
init \
"${@}"
}
2023-05-09 20:02:34 +00:00
# initialize a new bare repository
2024-11-17 15:59:22 +00:00
gib() { git_init_bare "${@}"; }
2024-11-17 12:58:39 +00:00
git_init_bare() {
2024-11-16 18:08:27 +00:00
git \
init \
--bare \
"${@}"
}
2023-05-09 20:02:34 +00:00
2024-11-16 19:27:36 +00:00
# log history
2024-11-17 15:59:22 +00:00
gl() { git_log "${@}"; }
2024-11-17 12:58:39 +00:00
git_log() {
2024-11-16 19:27:36 +00:00
git \
log \
--abbrev=8 \
--abbrev-commit \
2024-11-17 16:15:47 +00:00
--format="${GIT_LOG_FORMAT}" \
2024-11-16 19:27:36 +00:00
--graph \
"${@}"
}
2024-11-16 18:17:36 +00:00
# log all history
2024-11-17 15:59:22 +00:00
gla() { git_log_all "${@}"; }
2024-11-17 12:58:39 +00:00
git_log_all() {
2024-11-17 16:14:15 +00:00
git_log \
2024-11-16 18:17:36 +00:00
--all \
"${@}"
}
2024-11-16 19:27:36 +00:00
# log all history with patches
2024-11-17 15:59:22 +00:00
glap() { git_log_all_patch "${@}"; }
2024-11-17 12:58:39 +00:00
git_log_all_patch() {
2024-11-17 16:14:15 +00:00
git_log \
2024-11-16 19:27:36 +00:00
--all \
--patch \
2024-11-16 18:17:36 +00:00
"${@}"
}
2023-05-09 20:02:34 +00:00
2024-11-16 19:27:36 +00:00
# log history with patches
2024-11-17 15:59:22 +00:00
glp() { git_log_patch "${@}"; }
2024-11-17 12:58:39 +00:00
git_log_patch() {
2024-11-17 16:14:15 +00:00
git_log \
2024-11-16 19:27:36 +00:00
--patch \
"${@}"
}
2023-05-09 20:02:34 +00:00
2024-11-17 12:59:52 +00:00
# fast-forward merge to remote branch
2024-11-17 15:59:22 +00:00
gm() { git_merge "${@}"; }
2024-11-17 12:59:52 +00:00
git_merge() {
git \
merge \
--ff-only \
"${@}"
}
2023-05-14 20:29:47 +00:00
# abort the current merge commit
2024-11-17 15:59:22 +00:00
gma() { git_merge_abort "${@}"; }
2024-11-17 12:58:39 +00:00
git_merge_abort() {
2024-11-17 01:26:32 +00:00
git \
merge \
--abort \
"${@}"
}
2023-05-09 20:02:34 +00:00
# do a merge commit
2024-11-17 15:59:22 +00:00
gmc() { git_merge_commit "${@}"; }
2024-11-17 12:58:39 +00:00
git_merge_commit() {
2024-11-17 01:26:32 +00:00
git \
merge \
--no-ff \
--message \
"${@}"
}
2023-05-09 20:02:34 +00:00
# squash a branch and index its modifications
2024-11-17 15:59:22 +00:00
gms() { git_merge_squash "${@}"; }
2024-11-17 13:20:55 +00:00
git_merge_squash() {
2024-11-17 01:26:32 +00:00
git \
merge \
--squash \
"${@}"
}
2023-05-09 20:02:34 +00:00
# merge via external tool
2024-11-17 15:59:22 +00:00
gmt() { git_merge_tool "${@}"; }
2024-11-17 13:20:55 +00:00
git_merge_tool() {
2024-11-17 01:26:32 +00:00
git \
mergetool \
"${@}"
}
2023-05-09 20:02:34 +00:00
# push to the remote repository
2024-11-17 15:59:22 +00:00
gp() { git_push "${@}"; }
2024-11-17 13:20:55 +00:00
git_push() {
2024-11-17 01:31:52 +00:00
git \
push \
--tags \
--verbose \
"${@}"
}
2023-05-09 20:02:34 +00:00
# delete from the remote repository
2024-11-17 15:59:22 +00:00
gpd() { git_push_delete "${@}"; }
2024-11-17 13:20:55 +00:00
git_push_delete() {
2024-11-17 01:31:52 +00:00
git \
push \
--delete \
"${@}"
}
2023-05-09 20:02:34 +00:00
# force the push to the remote repository
2024-11-17 15:59:22 +00:00
gpf() { git_push_force "${@}"; }
2024-11-17 13:20:55 +00:00
git_push_force() {
2024-11-17 16:14:15 +00:00
git_push \
2024-11-17 01:31:52 +00:00
--force \
"${@}"
}
2023-05-09 20:02:34 +00:00
# rebase current branch onto another
2024-11-17 15:59:22 +00:00
grb() { git_re_base "${@}"; }
2024-11-17 13:20:55 +00:00
git_re_base() {
2024-11-17 01:45:45 +00:00
git \
rebase \
"${@}"
}
2023-05-09 20:02:34 +00:00
# abort current rebase
2024-11-17 15:59:22 +00:00
grba() { git_re_base_abort "${@}"; }
2024-11-17 13:20:55 +00:00
git_re_base_abort() {
2024-11-17 01:45:45 +00:00
git \
rebase \
--abort \
"${@}"
}
2023-05-09 20:02:34 +00:00
# continue current rebase
2024-11-17 15:59:22 +00:00
grbc() { git_re_base_continue "${@}"; }
2024-11-17 13:20:55 +00:00
git_re_base_continue() {
2024-11-17 01:45:45 +00:00
git \
rebase \
--continue \
"${@}"
}
2023-05-09 20:02:34 +00:00
# force rebase without fast-forward
2024-11-17 15:59:22 +00:00
grbf() { git_re_base_force "${@}"; }
2024-11-17 13:20:55 +00:00
git_re_base_force() {
2024-11-17 01:45:45 +00:00
git \
rebase \
--force-rebase \
"${@}"
}
2023-05-09 20:02:34 +00:00
# rebase interactively
2024-11-17 15:59:22 +00:00
grbi() { git_re_base_interactive "${@}"; }
2024-11-17 13:20:55 +00:00
git_re_base_interactive() {
2024-11-17 01:45:45 +00:00
git \
rebase \
--interactive \
"${@}"
}
2023-05-09 20:02:34 +00:00
# add a new remote repository
2024-11-17 15:59:22 +00:00
grma() { git_re_mote_add "${@}"; }
2024-11-17 13:20:55 +00:00
git_re_mote_add() {
2024-11-17 01:53:03 +00:00
git \
remote \
add \
"${@}"
}
2023-05-09 20:02:34 +00:00
# list remote repositories
2024-11-17 15:59:22 +00:00
grml() { git_re_mote_list "${@}"; }
2024-11-17 13:20:55 +00:00
git_re_mote_list() {
2024-11-17 01:53:03 +00:00
git \
remote \
--verbose \
"${@}"
}
2023-05-09 20:02:34 +00:00
2024-11-17 16:08:46 +00:00
# set the location of a remote repository
grmsu() { git_re_mote_set_upstream "${@}"; }
git_re_mote_set_upstream() {
2024-11-17 02:59:26 +00:00
git \
remote \
2024-11-17 16:08:46 +00:00
set-url \
2024-11-17 02:59:26 +00:00
"${@}"
}
2024-11-17 16:08:46 +00:00
# show connection to a remote repository
grms() { git_re_mote_show "${@}"; }
git_re_mote_show() {
2024-11-17 01:53:03 +00:00
git \
remote \
2024-11-17 16:08:46 +00:00
show \
2024-11-17 01:53:03 +00:00
"${@}"
}
2023-05-09 20:02:34 +00:00
2024-11-17 16:03:30 +00:00
# remove and add removal to index
grm() { git_re_move "${@}"; }
git_re_move() {
git \
rm \
"${@}"
}
2023-05-09 20:02:34 +00:00
# remove file(s) from index or move current branch pointer
2024-11-17 15:59:22 +00:00
grs() { git_re_set "${@}"; }
2024-11-17 13:20:55 +00:00
git_re_set() {
2024-11-17 01:54:03 +00:00
git \
reset \
"${@}"
}
2023-05-09 20:02:34 +00:00
# wipe modifications or reset current branch to another commit
2024-11-17 15:59:22 +00:00
grsh() { git_re_set_hard "${@}"; }
2024-11-17 13:20:55 +00:00
git_re_set_hard() {
2024-11-17 01:54:03 +00:00
git \
reset \
--hard \
"${@}"
}
2023-05-09 20:02:34 +00:00
2024-11-17 16:08:46 +00:00
# show a commit
gsc() { git_show_commit "${@}"; }
git_show_commit() {
git \
show \
"${@}"
}
2023-05-09 20:02:34 +00:00
# current state of repository
2024-11-17 15:59:22 +00:00
gs() { git_status "${@}"; }
2024-11-17 13:20:55 +00:00
git_status() {
2024-11-17 01:58:43 +00:00
git \
status \
--untracked-files="all" \
"${@}"
}
2023-05-09 20:02:34 +00:00
# tag a commit
2024-11-17 15:59:22 +00:00
gt() { git_tag "${@}"; }
2024-11-17 13:20:55 +00:00
git_tag() {
2024-11-17 01:55:45 +00:00
git \
tag \
"${@}"
}
2023-05-09 20:02:34 +00:00
# delete a tag
2024-11-17 15:59:22 +00:00
gtd() { git_tag_delete "${@}"; }
2024-11-17 13:20:55 +00:00
git_tag_delete() {
2024-11-17 01:55:45 +00:00
git \
tag \
--delete \
"${@}"
}