config/git: document some functions

This commit is contained in:
xerus2000 2020-11-13 12:49:24 +01:00
parent 6e32e49b4d
commit 81cf937da7
2 changed files with 7 additions and 3 deletions

View File

@ -105,7 +105,7 @@
unstage = reset HEAD -- unstage = reset HEAD --
gcr = !git gc && git repack -a -d gcr = !git gc && git repack -a -d
ready = rebase -i @{upstream} ready = rebase -i @{push}
format-head = !git stash && git-clang-format HEAD~ && git commit -a --amend --no-edit && git stash pop format-head = !git stash && git-clang-format HEAD~ && git commit -a --amend --no-edit && git stash pop
sm = submodule update --init --recursive sm = submodule update --init --recursive

View File

@ -53,17 +53,21 @@ gitrestore() {
git checkout -- "$@" git checkout -- "$@"
} }
# Branches # BRANCHES
# Cleans up remote branches and removes branches where the remote-tracking branches got removed.
alias gitrmgonebranches='git fetch -p && for branch in `git branch -vv | grep ": gone]" | cut -d" " -f3`; do git branch -D "$branch"; done' alias gitrmgonebranches='git fetch -p && for branch in `git branch -vv | grep ": gone]" | cut -d" " -f3`; do git branch -D "$branch"; done'
# Recreates the current or given branch with the state from master or another given branch.
gitrebranch() { gitrebranch() {
branch=${1:-$(git curbranch)} branch=${1:-$(git curbranch)}
test "$(git curbranch)" = "$branch" && git checkout ${2:-master} test "$(git curbranch)" = "$branch" && git checkout ${2:-master}
git branch -D $branch git branch -D $branch
git checkout -b $branch git checkout -b $branch
} }
# Removes the given branch locally and remotely.
# With no argument it switches to the default branch and deletes the current branch.
gitrmbranch() { gitrmbranch() {
branch=${1:-$(git curbranch)} branch=${1:-$(git curbranch)}
git push -d $(git rev-parse --abbrev-ref $branch@{u} | sed 's/\// /' || echo origin $branch) git push -d $(git rev-parse --abbrev-ref $branch@{push} | sed 's/\// /' || echo origin $branch)
test $1 || git checkout main || git checkout master || git checkout $(cat .git/refs/remotes/origin/HEAD | cut -d'/' -f4) test $1 || git checkout main || git checkout master || git checkout $(cat .git/refs/remotes/origin/HEAD | cut -d'/' -f4)
git branch -D $branch git branch -D $branch
} }