rwx/sh/alias/git.sh

549 lines
8.1 KiB
Bash
Raw Normal View History

2024-12-01 19:53:12 +01:00
RWX_GIT_LOG_FORMAT="\
2024-11-17 17:15:47 +01:00
%C(auto)%h%d
S %C(red)%GS
2024-11-17 17:24:17 +01:00
A %C(green)%an %ae
%C(green)%ai
C %C(blue)%cn %ce
%C(blue)%ci
2024-11-17 17:15:47 +01:00
%B"
2023-05-09 22:02:34 +02:00
# add to index
2024-11-19 14:42:11 +01:00
ga() { a__git_add "${@}"; }
a__git_add() {
2024-11-16 16:59:23 +01:00
git \
add \
"${@}"
}
2023-05-09 22:02:34 +02:00
# add all to index
2024-11-19 14:42:11 +01:00
gaa() { a__git_add_all "${@}"; }
a__git_add_all() {
2024-11-16 16:59:23 +01:00
git \
add \
--all \
"${@}"
}
2023-05-09 22:02:34 +02:00
2024-11-16 17:01:12 +01:00
# add parts of all to index
2024-11-19 14:42:11 +01:00
gaap() { a__git_add_all_patch "${@}"; }
a__git_add_all_patch() {
2024-11-16 17:01:12 +01:00
git \
add \
--all \
--patch \
"${@}"
}
2023-05-14 22:48:39 +02:00
# add parts to index
2024-11-19 14:42:11 +01:00
gap() { a__git_add_patch "${@}"; }
a__git_add_patch() {
2024-11-16 17:01:12 +01:00
git \
add \
--patch \
"${@}"
}
2023-05-14 22:48:39 +02:00
2023-05-09 22:02:34 +02:00
# create a branch
2024-11-19 14:42:11 +01:00
gb() { a__git_branch "${@}"; }
a__git_branch() {
2024-11-16 18:43:09 +01:00
git \
branch \
"${@}"
}
2023-05-09 22:02:34 +02:00
# delete a branch
2024-11-19 14:42:11 +01:00
gbd() { a__git_branch_delete "${@}"; }
a__git_branch_delete() {
2024-11-16 18:43:09 +01:00
git \
branch \
--delete \
"${@}"
}
2023-05-09 22:02:34 +02:00
# force a branch deletion
2024-11-19 14:42:11 +01:00
gbdf() { a__git_branch_delete_force "${@}"; }
a__git_branch_delete_force() {
2024-11-16 18:43:09 +01:00
git \
branch \
--delete \
--force \
"${@}"
}
2023-05-09 22:02:34 +02:00
# list branches
2024-11-19 14:42:11 +01:00
gbl() { a__git_branch_list "${@}"; }
a__git_branch_list() {
2024-11-16 18:43:09 +01:00
git \
branch \
--all \
--list \
--verbose \
--verbose \
"${@}"
}
2023-05-09 22:02:34 +02:00
# set the link to a remote branch from a local branch
2024-11-19 14:42:11 +01:00
gbsu() { a__git_branch_set_upstream "${@}"; }
a__git_branch_set_upstream() {
2024-11-16 18:43:09 +01:00
git \
branch \
--set-upstream-to \
"${@}"
}
2023-05-09 22:02:34 +02:00
# switch to a branch or checkout file(s) from a commit
2024-11-19 14:42:11 +01:00
gc() { a__git_checkout "${@}"; }
a__git_checkout() {
2024-11-16 18:51:33 +01:00
git \
checkout \
"${@}"
}
2023-05-09 22:02:34 +02:00
# checkout an orphan branch
2024-11-19 14:42:11 +01:00
gco() { a__git_checkout_orphan "${@}"; }
a__git_checkout_orphan() {
2024-11-16 18:51:33 +01:00
git \
checkout \
--orphan \
"${@}"
}
2023-05-09 22:02:34 +02:00
# pick a commit
2024-11-19 14:42:11 +01:00
gcp() { a__git_cherry_pick "${@}"; }
a__git_cherry_pick() {
2024-11-16 18:51:33 +01:00
git \
cherry-pick \
"${@}"
}
2023-05-09 22:02:34 +02:00
# abort the commit pick
2024-11-19 14:42:11 +01:00
gcpa() { a__git_cherry_pick_abort "${@}"; }
a__git_cherry_pick_abort() {
2024-11-16 18:51:33 +01:00
git \
cherry-pick \
--abort \
"${@}"
}
2023-05-09 22:02:34 +02:00
# continue the commit pick
2024-11-19 14:42:11 +01:00
gcpc() { a__git_cherry_pick_continue "${@}"; }
a__git_cherry_pick_continue() {
2024-11-16 18:51:33 +01:00
git \
cherry-pick \
--continue \
"${@}"
}
2023-05-09 22:02:34 +02:00
2024-11-17 17:05:44 +01:00
# clean untracked files
2024-11-19 14:42:11 +01:00
gcf() { a__git_clean_force "${@}"; }
a__git_clean_force() {
2024-11-17 17:05:44 +01:00
git \
clean \
-d \
--force \
"${@}"
}
# redo the last commit with a different message
2024-11-19 14:42:11 +01:00
gcam() { a__git_commit_amend_message "${@}"; }
a__git_commit_amend_message() {
2024-11-17 17:05:44 +01:00
git \
commit \
--amend \
--message \
"${@}"
}
# make a root commit
2024-11-19 14:42:11 +01:00
gcem() { a__git_commit_empty_message "${@}"; }
a__git_commit_empty_message() {
2024-11-17 17:05:44 +01:00
git \
commit \
--allow-empty \
--allow-empty-message \
--message \
"${@}"
}
# commit the index
2024-11-19 14:42:11 +01:00
gcm() { a__git_commit_message "${@}"; }
a__git_commit_message() {
2024-11-17 17:05:44 +01:00
git \
commit \
--message \
"${@}"
}
2023-05-09 22:02:34 +02:00
# configure the user email
2024-11-19 14:42:11 +01:00
gcue() { a__git_config_user_email "${@}"; }
a__git_config_user_email() {
2024-11-16 18:54:56 +01:00
git \
config \
"user.email" \
"${@}"
}
# configure the user name
2024-11-19 14:42:11 +01:00
gcun() { a__git_config_user_name "${@}"; }
a__git_config_user_name() {
2024-11-16 18:54:56 +01:00
git \
config \
"user.name" \
"${@}"
}
2023-05-09 22:02:34 +02:00
# differences from last or between commits
2024-11-19 14:42:11 +01:00
gd() { a__git_diff "${@}"; }
a__git_diff() {
2024-11-16 19:01:27 +01:00
git \
diff \
"${@}"
}
2023-05-09 22:02:34 +02:00
# display what is indexed in cache
2024-11-19 14:42:11 +01:00
gdc() { a__git_diff_cached "${@}"; }
a__git_diff_cached() {
2024-11-16 19:01:27 +01:00
git \
diff \
--cached \
"${@}"
}
2023-05-09 22:02:34 +02:00
# indexed character-level differences
2024-11-19 14:42:11 +01:00
gdcw() { a__git_diff_cached_word "${@}"; }
a__git_diff_cached_word() {
2024-11-16 19:01:27 +01:00
git \
diff \
--cached \
--word-diff-regex "." \
"${@}"
}
2023-05-09 22:02:34 +02:00
# differences via external tool
2024-11-19 14:42:11 +01:00
gdt() { a__git_diff_tool "${@}"; }
a__git_diff_tool() {
2024-11-16 19:01:27 +01:00
git \
difftool \
--dir-diff \
"${@}"
}
2023-05-09 22:02:34 +02:00
# character-level differences
2024-11-19 14:42:11 +01:00
gdw() { a__git_diff_word "${@}"; }
a__git_diff_word() {
2024-11-16 19:01:27 +01:00
git \
diff \
--word-diff-regex "." \
"${@}"
}
2023-05-09 22:02:34 +02:00
# fetch from the remote repository
2024-11-19 14:42:11 +01:00
gf() { a__git_fetch "${@}"; }
a__git_fetch() {
2024-12-01 18:07:54 +01:00
rwx_gpg_agent_update &&
git \
fetch \
--tags \
--verbose \
"${@}"
2024-11-16 19:02:56 +01:00
}
2023-05-09 22:02:34 +02:00
# fetch from remote repository and prune local orphan branches
2024-11-19 14:42:11 +01:00
gfp() { a__git_fetch_prune "${@}"; }
a__git_fetch_prune() {
a__git_fetch \
2024-11-16 19:02:56 +01:00
--prune \
"${@}"
}
2023-05-09 22:02:34 +02:00
# garbage collect all orphan commits
2024-11-19 14:42:11 +01:00
ggc() { a__git_garbage_collect "${@}"; }
a__git_garbage_collect() {
2024-11-16 19:07:11 +01:00
git \
reflog \
expire \
--all \
--expire "all" &&
git \
gc \
--aggressive \
--prune="now"
}
2023-05-09 22:02:34 +02:00
# initialize a new repository
2024-11-19 14:42:11 +01:00
gi() { a__git_init "${@}"; }
a__git_init() {
2024-11-16 19:08:27 +01:00
git \
init \
"${@}"
}
2023-05-09 22:02:34 +02:00
# initialize a new bare repository
2024-11-19 14:42:11 +01:00
gib() { a__git_init_bare "${@}"; }
a__git_init_bare() {
2024-11-16 19:08:27 +01:00
git \
init \
--bare \
"${@}"
}
2023-05-09 22:02:34 +02:00
2024-11-16 20:27:36 +01:00
# log history
2024-11-19 14:42:11 +01:00
gl() { a__git_log "${@}"; }
a__git_log() {
2024-11-16 20:27:36 +01:00
git \
log \
--abbrev=8 \
--abbrev-commit \
2024-12-01 19:53:12 +01:00
--format="${RWX_GIT_LOG_FORMAT}" \
2024-11-16 20:27:36 +01:00
--graph \
"${@}"
}
2024-11-16 19:17:36 +01:00
# log all history
2024-11-19 14:42:11 +01:00
gla() { a__git_log_all "${@}"; }
a__git_log_all() {
a__git_log \
2024-11-16 19:17:36 +01:00
--all \
"${@}"
}
2024-11-16 20:27:36 +01:00
# log all history with patches
2024-11-19 14:42:11 +01:00
glap() { a__git_log_all_patch "${@}"; }
a__git_log_all_patch() {
a__git_log \
2024-11-16 20:27:36 +01:00
--all \
--patch \
2024-11-16 19:17:36 +01:00
"${@}"
}
2023-05-09 22:02:34 +02:00
2024-11-16 20:27:36 +01:00
# log history with patches
2024-11-19 14:42:11 +01:00
glp() { a__git_log_patch "${@}"; }
a__git_log_patch() {
a__git_log \
2024-11-16 20:27:36 +01:00
--patch \
"${@}"
}
2023-05-09 22:02:34 +02:00
2024-11-17 13:59:52 +01:00
# fast-forward merge to remote branch
2024-11-19 14:42:11 +01:00
gm() { a__git_merge "${@}"; }
a__git_merge() {
2024-11-17 13:59:52 +01:00
git \
merge \
--ff-only \
"${@}"
}
2023-05-14 22:29:47 +02:00
# abort the current merge commit
2024-11-19 14:42:11 +01:00
gma() { a__git_merge_abort "${@}"; }
a__git_merge_abort() {
2024-11-17 02:26:32 +01:00
git \
merge \
--abort \
"${@}"
}
2023-05-09 22:02:34 +02:00
# do a merge commit
2024-11-19 14:42:11 +01:00
gmc() { a__git_merge_commit "${@}"; }
a__git_merge_commit() {
2024-11-17 02:26:32 +01:00
git \
merge \
--no-ff \
--message \
"${@}"
}
2023-05-09 22:02:34 +02:00
# squash a branch and index its modifications
2024-11-19 14:42:11 +01:00
gms() { a__git_merge_squash "${@}"; }
a__git_merge_squash() {
2024-11-17 02:26:32 +01:00
git \
merge \
--squash \
"${@}"
}
2023-05-09 22:02:34 +02:00
# merge via external tool
2024-11-19 14:42:11 +01:00
gmt() { a__git_merge_tool "${@}"; }
a__git_merge_tool() {
2024-11-17 02:26:32 +01:00
git \
mergetool \
"${@}"
}
2023-05-09 22:02:34 +02:00
# push to the remote repository
2024-11-19 14:42:11 +01:00
gp() { a__git_push "${@}"; }
a__git_push() {
2024-12-01 18:06:02 +01:00
rwx_gpg_agent_update &&
git \
push \
--tags \
--verbose \
"${@}"
2024-11-17 02:31:52 +01:00
}
2023-05-09 22:02:34 +02:00
# delete from the remote repository
2024-11-19 14:42:11 +01:00
gpd() { a__git_push_delete "${@}"; }
a__git_push_delete() {
2024-11-17 02:31:52 +01:00
git \
push \
--delete \
"${@}"
}
2023-05-09 22:02:34 +02:00
# force the push to the remote repository
2024-11-19 14:42:11 +01:00
gpf() { a__git_push_force "${@}"; }
a__git_push_force() {
a__git_push \
2024-11-17 02:31:52 +01:00
--force \
"${@}"
}
2023-05-09 22:02:34 +02:00
# rebase current branch onto another
2024-11-19 14:42:11 +01:00
grb() { a__git_re_base "${@}"; }
a__git_re_base() {
2024-11-17 02:45:45 +01:00
git \
rebase \
"${@}"
}
2023-05-09 22:02:34 +02:00
# abort current rebase
2024-11-19 14:42:11 +01:00
grba() { a__git_re_base_abort "${@}"; }
a__git_re_base_abort() {
2024-11-17 02:45:45 +01:00
git \
rebase \
--abort \
"${@}"
}
2023-05-09 22:02:34 +02:00
# continue current rebase
2024-11-19 14:42:11 +01:00
grbc() { a__git_re_base_continue "${@}"; }
a__git_re_base_continue() {
2024-11-17 02:45:45 +01:00
git \
rebase \
--continue \
"${@}"
}
2023-05-09 22:02:34 +02:00
# force rebase without fast-forward
2024-11-19 14:42:11 +01:00
grbf() { a__git_re_base_force "${@}"; }
a__git_re_base_force() {
2024-11-17 02:45:45 +01:00
git \
rebase \
--force-rebase \
"${@}"
}
2023-05-09 22:02:34 +02:00
# rebase interactively
2024-11-19 14:42:11 +01:00
grbi() { a__git_re_base_interactive "${@}"; }
a__git_re_base_interactive() {
2024-11-17 02:45:45 +01:00
git \
rebase \
--interactive \
"${@}"
}
2023-05-09 22:02:34 +02:00
# add a new remote repository
2024-11-19 14:42:11 +01:00
grma() { a__git_re_mote_add "${@}"; }
a__git_re_mote_add() {
2024-11-17 02:53:03 +01:00
git \
remote \
add \
"${@}"
}
2023-05-09 22:02:34 +02:00
# list remote repositories
2024-11-19 14:42:11 +01:00
grml() { a__git_re_mote_list "${@}"; }
a__git_re_mote_list() {
2024-11-17 02:53:03 +01:00
git \
remote \
--verbose \
"${@}"
}
2023-05-09 22:02:34 +02:00
2024-11-17 17:08:46 +01:00
# set the location of a remote repository
2024-11-19 14:42:11 +01:00
grmsu() { a__git_re_mote_set_upstream "${@}"; }
a__git_re_mote_set_upstream() {
2024-11-17 03:59:26 +01:00
git \
remote \
2024-11-17 17:08:46 +01:00
set-url \
2024-11-17 03:59:26 +01:00
"${@}"
}
2024-11-17 17:08:46 +01:00
# show connection to a remote repository
2024-11-19 14:42:11 +01:00
grms() { a__git_re_mote_show "${@}"; }
a__git_re_mote_show() {
2024-11-17 02:53:03 +01:00
git \
remote \
2024-11-17 17:08:46 +01:00
show \
2024-11-17 02:53:03 +01:00
"${@}"
}
2023-05-09 22:02:34 +02:00
2024-11-17 17:03:30 +01:00
# remove and add removal to index
2024-11-19 14:42:11 +01:00
grm() { a__git_re_move "${@}"; }
a__git_re_move() {
2024-11-17 17:03:30 +01:00
git \
rm \
"${@}"
}
2023-05-09 22:02:34 +02:00
# remove file(s) from index or move current branch pointer
2024-11-19 14:42:11 +01:00
grs() { a__git_re_set "${@}"; }
a__git_re_set() {
2024-11-17 02:54:03 +01:00
git \
reset \
"${@}"
}
2023-05-09 22:02:34 +02:00
# wipe modifications or reset current branch to another commit
2024-11-19 14:42:11 +01:00
grsh() { a__git_re_set_hard "${@}"; }
a__git_re_set_hard() {
2024-11-17 02:54:03 +01:00
git \
reset \
--hard \
"${@}"
}
2023-05-09 22:02:34 +02:00
2024-11-17 17:08:46 +01:00
# show a commit
2024-11-19 14:42:11 +01:00
gsc() { a__git_show_commit "${@}"; }
a__git_show_commit() {
2024-11-17 17:08:46 +01:00
git \
show \
"${@}"
}
2023-05-09 22:02:34 +02:00
# current state of repository
2024-11-19 14:42:11 +01:00
gs() { a__git_status "${@}"; }
a__git_status() {
2024-11-17 02:58:43 +01:00
git \
status \
--untracked-files="all" \
"${@}"
}
2023-05-09 22:02:34 +02:00
# tag a commit
2024-11-19 14:42:11 +01:00
gt() { a__git_tag "${@}"; }
a__git_tag() {
2024-11-17 02:55:45 +01:00
git \
tag \
"${@}"
}
2023-05-09 22:02:34 +02:00
# delete a tag
2024-11-19 14:42:11 +01:00
gtd() { a__git_tag_delete "${@}"; }
a__git_tag_delete() {
2024-11-17 02:55:45 +01:00
git \
tag \
--delete \
"${@}"
}
2024-12-01 17:59:08 +01:00
# update head ref
gurh() { a__git_update_ref_head "${@}"; }
a__git_update_ref_head() {
2024-12-01 18:11:09 +01:00
if [ -n "${2}" ]; then
2024-12-01 17:59:08 +01:00
git \
update-ref \
"refs/heads/${1}" \
"${2}"
fi
}