Skip to content

Commit 808243b

Browse files
bebeheiStunkymonkey
authored andcommitted
Add git-rewrite-commits
1 parent ad24ebe commit 808243b

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

bin/git-rewrite-commits.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env bash
2+
3+
# Automatically start a rebase for all commits between HEAD and the main
4+
# branch without integrating new commits from the main branch
5+
#
6+
# Technically it's a git rebase without rebasing any commits.
7+
8+
# Enforce being in a git repository
9+
git rev-parse --is-inside-work-tree >/dev/null || exit $?
10+
11+
# We actually should check out the head branch via `git remote show ${REMOTE}`,
12+
# but this requires active connection and active 2FA verification. Tedious to
13+
# have multiple calls for this
14+
if git rev-parse --verify main &>/dev/null; then
15+
MAIN_BRANCH=main
16+
else
17+
MAIN_BRANCH=master
18+
fi
19+
20+
CURRENT_BRANCH="$(git rev-parse --abbrev-ref HEAD)"
21+
22+
if [ "${CURRENT_BRANCH}" = "${MAIN_BRANCH}" ]; then
23+
echo "Cannot rebase commits from '${CURRENT_BRANCH}' (HEAD) onto '${MAIN_BRANCH}'" >&2
24+
exit 1
25+
fi
26+
27+
MERGE_BASE="$(git merge-base "${MAIN_BRANCH}" HEAD)"
28+
29+
# Show the next command
30+
set -x
31+
32+
git rebase --interactive "${MERGE_BASE}"

install.conf.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
~/.local/bin/host-is-on: bin/host-is-on.sh
7878
~/.local/bin/git-authors: bin/git-authors.sh
7979
~/.local/bin/git-ard: bin/git-ard.sh
80+
~/.local/bin/git-rewrite-commits: bin/git-rewrite-commits.sh
8081
~/.local/bin/clean: bin/clean.sh
8182

8283
# systemd

0 commit comments

Comments
 (0)