Prefer "main" to "master"
See
1e7fa50da0
.
> This commit introduces `git-master-to-main-wrapper`, which seamlessly
prefers `main` to `master` but works fine with repos that do use
a `master` branch.
This commit is contained in:
parent
2e8c717036
commit
0f797c6ffe
19
bin/git-master-to-main-wrapper
Executable file
19
bin/git-master-to-main-wrapper
Executable file
|
@ -0,0 +1,19 @@
|
|||
#!/usr/bin/env zsh
|
||||
|
||||
# Usage: instead of
|
||||
#
|
||||
# git rebase -i master
|
||||
#
|
||||
# run this:
|
||||
#
|
||||
# git master-to-main-wrapper rebase -i %BRANCH%
|
||||
#
|
||||
# It will replace the literal string `%BRANCH%` with "main" (preferred) or
|
||||
# "master" depending on what the current repository uses.
|
||||
|
||||
command=$*
|
||||
branchname=$(main-or-master-branch)
|
||||
replaced_commands=$(echo $command | sed "s/%BRANCH%/$branchname/g")
|
||||
# sh_glob ignores special meaning of parentheses so that fancy logs like this
|
||||
# work: `git master-to-main-wrapper log --format='%w(78)%s%n%+b'`
|
||||
zsh -c "setopt sh_glob; git ${replaced_commands}"
|
10
bin/main-or-master-branch
Executable file
10
bin/main-or-master-branch
Executable file
|
@ -0,0 +1,10 @@
|
|||
#!/bin/zsh
|
||||
|
||||
# Check if we should use the `main` or `master` branch for this repo.
|
||||
# Prefer `main` to `master`.
|
||||
|
||||
if git show-ref --quiet origin/main || git rev-parse main &>/dev/null; then
|
||||
echo main
|
||||
else
|
||||
echo master
|
||||
fi
|
|
@ -15,7 +15,7 @@
|
|||
dup = !git checkout develop && git fetch origin && echo && git sl develop..origin/develop && echo && git pull --quiet && git checkout -
|
||||
fixup = commit --fixup
|
||||
issues = !hub browse -- issues
|
||||
mup = !git checkout master && git fetch origin && echo && git sl master..origin/master && echo && git pull --quiet && git checkout -
|
||||
mup = !git master-to-main-wrapper checkout %BRANCH% && git fetch origin && echo && git sl %BRANCH%..origin/%BRANCH% && echo && git pull --quiet && git checkout -
|
||||
nah = !git reset --hard && git clean -fd
|
||||
no-ff = merge --no-ff
|
||||
pl = pull
|
||||
|
@ -26,10 +26,10 @@
|
|||
rdup = !git dup && git rebase develop
|
||||
remotes = remote -v
|
||||
repush = !git pull --rebase && git push
|
||||
rmup = !git mup && git rebase master
|
||||
rmup = !git mup && git master-to-main-wrapper rebase %BRANCH%
|
||||
ri = rebase --interactive
|
||||
rid = !git rebase -i $(git merge-base develop HEAD)
|
||||
rim = !git rebase -i $(git merge-base master HEAD)
|
||||
rim = !git rebase -i $(git master-to-main-wrapper merge-base %BRANCH% HEAD)
|
||||
riu = !git rebase -i $(git rev-parse --abbrev-ref --symbolic-full-name @{u})
|
||||
sl = log --oneline --decorate -20
|
||||
sla = log --oneline --decorate --graph --all -20
|
||||
|
|
|
@ -1,7 +1,14 @@
|
|||
# No arguments: `git status`
|
||||
# With arguments: acts like `git`
|
||||
g() {
|
||||
if [[ $# > 0 ]]; then
|
||||
if [[ $1 == init ]];
|
||||
then
|
||||
# Prefer "main" to "master"
|
||||
git "$@"
|
||||
git checkout -b main
|
||||
git branch -d master
|
||||
elif [[ $# > 0 ]];
|
||||
then
|
||||
git $@
|
||||
else
|
||||
git status --short --branch
|
||||
|
|
Loading…
Reference in a new issue