Skip to content

Commit d32f517

Browse files
committed
2024 updates
1 parent d38c3b7 commit d32f517

File tree

5 files changed

+60
-31
lines changed

5 files changed

+60
-31
lines changed

git-co

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#/bin/bash
2+
3+
STASH=$(git stash create)
4+
5+
branch_list=$(git for-each-ref --sort=-committerdate --format='%(refname:short)' refs/heads/ | grep -v -e "^$")
6+
git checkout $(echo "$branch_list" | fzf --preview 'git show --color {}')
7+
8+
if [[ -n $STASH ]]; then
9+
git stash apply $STASH
10+
fi

git-list-autostash

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
# finds detached autostash commits
4+
git fsck --no-reflog \
5+
| awk '/dangling commit/ {print $3}' \
6+
| xargs -n1 git log --pretty='%h %s' -p -1

git-remaster

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
#
55
# git-remaster
66
#
7-
# Rebases the current branch and updates the main branch at the same time,
8-
# preserving staged and unstaged changes in both.
7+
# Updates the master branch without having to checkout, and then rebases the
8+
# current feature branch on top of the latest commits in master
99
#
1010
# git checkout my-branch
1111
# git remaster
@@ -17,33 +17,10 @@ set -e
1717
MAIN_BRANCH=$(git symbolic-ref refs/remotes/origin/HEAD --short | sed 's,origin/,,')
1818
BRANCH=$(git rev-parse --abbrev-ref HEAD)
1919

20-
if [ -z $MAIN_BRANCH ]; then
21-
echo "No master/trunk branch found."
22-
exit 1
23-
fi
24-
25-
# save current state to a detached commit object and reset
26-
RSTASH=$(git stash create --include-untracked)
20+
echo "Updating $MAIN_BRANCH branch..."
21+
git pull origin $MAIN_BRANCH:$MAIN_BRANCH --rebase --autostash
2722

28-
if [[ $RSTASH ]]; then
29-
echo "Stashed $RSTASH"
30-
git stash store -m "Remaster on branch $BRANCH $(date)" "$RSTASH"
31-
git reset --hard
32-
fi
33-
34-
# fetch updates
35-
if git fetch --no-tags origin $MAIN_BRANCH; then
36-
# if not on master branch, check it out, update and return to branch
37-
if [[ $BRANCH != $MAIN_BRANCH ]]; then
38-
git checkout $MAIN_BRANCH
39-
git rebase origin/HEAD --rebase-merges --autostash
40-
git checkout -
41-
fi
42-
# rebase changes on top of origin/master
43-
git rebase origin/$MAIN_BRANCH --rebase-merges
44-
fi
45-
46-
# bring back stash if available, hide errors when empty
47-
if test $RSTASH; then
48-
git stash apply $RSTASH
49-
fi
23+
if [[ $BRANCH == $MAIN_BRANCH ]]; then exit 0; fi
24+
25+
echo "Rebasing $BRANCH on top of master..."
26+
git rebase origin/$MAIN_BRANCH --rebase-merges --autostash

git-remaster.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
This doesn't work, git pull fails because of ff-only config in .gitconfig
2+
3+
git pull origin $MAIN_BRANCH:$MAIN_BRANCH --rebase --autostash
4+
git rebase origin/$MAIN_BRANCH --rebase-merges --autostash
5+
6+
can't use `git rebase` directly from origin
7+
can't use `git fetch branch:branch` as it doesn't take rebase arg
8+
9+
so the only solution is to stash manually before, as the script does.

git-review

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bash
2+
3+
TARGET=${1:-diff}
4+
5+
preview () {
6+
fzf --preview 'bat --color=always --style=header,grid,changes --line-range :500 {2}'
7+
}
8+
9+
10+
usage () {
11+
echo "
12+
Usage:
13+
git review
14+
git review [hash]
15+
"
16+
}
17+
18+
if [[ $TARGET = "diff" ]]; then
19+
git status -s | preview
20+
elif [[ -n $TARGET ]]; then
21+
if git show-ref -q $TARGET; then
22+
git diff --name-only $TARGET | preview
23+
else
24+
usage
25+
exit 1
26+
fi
27+
fi

0 commit comments

Comments
 (0)