summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Bobov <anton@bobov.name>2026-08-26 21:12:45 +0500
committerAnton Bobov <anton@bobov.name>2026-08-26 21:12:45 +0500
commit4e505b4244fc466cfc88183abfe110d77ccfc3ca (patch)
tree205c80ab112cca21449231225b271d8ecd62f53a
parent6cc90e320ff6660677708efaeac121fea699c082 (diff)
git-keep: add script for merge/rebase conflict resolution
-rwxr-xr-xgit-keep34
1 files changed, 34 insertions, 0 deletions
diff --git a/git-keep b/git-keep
new file mode 100755
index 0000000..4f5ab29
--- /dev/null
+++ b/git-keep
@@ -0,0 +1,34 @@
+#!/usr/bin/env bash
+
+set -euo pipefail
+
+# @describe Keep your changes or incoming changes during merge/rebase conflicts
+# @meta version 1.0.0
+# @meta require-tools git
+
+is_rebase() {
+ [ -d "$(git rev-parse --git-path rebase-merge 2>/dev/null)" ] || [ -d "$(git rev-parse --git-path rebase-apply 2>/dev/null)" ]
+}
+
+do_keep() {
+ local ours="$1" theirs="$2"
+ shift 2
+ if is_rebase; then
+ git checkout --"$theirs" "$@"
+ else
+ git checkout --"$ours" "$@"
+ fi
+ git add "$@"
+}
+
+# @cmd Keep your current branch changes for specified files
+mine() {
+ do_keep "ours" "theirs" "${@:-.}"
+}
+
+# @cmd Keep incoming branch changes for specified files
+incoming() {
+ do_keep "theirs" "ours" "${@:-.}"
+}
+
+eval "$(argc --argc-eval "$0" "$@")"