Skip to content

Commit

Permalink
add git-default-branch
Browse files Browse the repository at this point in the history
  • Loading branch information
minrk committed Apr 13, 2021
1 parent 9acadfe commit 9a680ce
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
6 changes: 3 additions & 3 deletions aliases
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ alias remote='git remote add'
alias cherry='git cherry-pick'
alias pick='git cherry-pick'
alias submodule='git submodule init && git submodule update'
alias m="git checkout master"
alias mp="git checkout master && git pull"
alias m='git checkout $(git default-branch)'
alias mp='git checkout $(git default-branch) && git pull'
alias b="git checkout -b"
alias ci='git commit'
alias c="git fuzzy-checkout"
alias co="git fuzzy-checkout"
alias c-="git-last-branch"
alias pr="git push mine && hub pull-request"
alias uncommit="git log -1 && git reset HEAD^1"
alias rebase='git rebase -i origin/master'
alias rebase='git rebase -i origin/$(git default-branch)'
alias fork='hub fork && hub remote add -p mine $(hub config --get github.user)'
alias pm='git push mine'
alias gitx='open -a Fork .'
23 changes: 23 additions & 0 deletions bin/git-default-branch
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/sh
set -euo pipefail

# this takes a while with git remote show origin, so cache result

if [ "${1:-}" == "-f" ]; then
git config --unset-all defaultbranch.branch
else
branch="$(git config --get defaultbranch.branch || true)"
fi

if [ ! -z "${branch:-}" ]; then
echo $branch
exit 0
fi

# print $NF prints the last item
# line looks like:
# HEAD branch: main
branch=$(git remote show origin | grep 'HEAD branch' | awk '{print $NF}')

git config --add defaultbranch.branch "$branch"
echo $branch

0 comments on commit 9a680ce

Please sign in to comment.