Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions docs/lib/git.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ Rebase source branch onto target branch and forcefully push the rebased branch t

```
ggit-base SOURCE [TARGET] [REMOTE]
ggit-base SOURCE... TARGET REMOTE

Params:
SOURCE Branch to be rebased
TARGET Rebase onto this branch. Defaults to 'main'.
REMOTE Remote repository to pull and push. Defaults to 'origin'.
TARGET Rebase onto this branch. Defaults to 'main' in the first form.
REMOTE Remote repository to pull and push. Defaults to 'origin' in the first form.
```

---
Expand Down
27 changes: 19 additions & 8 deletions lib/git.sh
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,29 @@ ggit-diff() {
## @default origin
########################################
ggit-base() {
local branch_src="${1?:Branch to rebase missing}"
local branch_src=("${1?:Branch to rebase missing}")
local branch_onto="${2:-main}"
local remote="${3:-origin}"
local branch

print-header Switch to "${branch_src}"
git switch "${branch_src}" || return 1
print-header Rebase "${branch_src}" onto "${branch_onto}"
git rebase "${branch_onto}" || return 1
print-header Push "${branch_src}"
git push "${remote}" "+${branch_src}" || return 1
# If more than 3 arguments supplied
# last 2 arguments are branch_onto and remote the rest are branch_src
if [[ $# -gt 3 ]]; then
branch_onto="${*: -2:1}"
remote="${*: -1}"
branch_src=("${@:1:$#-2}")
fi

for branch in "${branch_src[@]}"; do
print-header Switch to "${branch}"
git checkout "${branch}" || return 1
print-header Rebase "${branch}" onto "${branch_onto}"
git rebase "${branch_onto}" || return 1
print-header Push "${branch}"
git push "${remote}" "+${branch}" || return 1
done
print-header Switch to "${branch_onto}"
git switch "${branch_onto}" || return 1
git checkout "${branch_onto}" || return 1
}

## Create tag & push
Expand Down