Git-rebranch is my git workflow that's a lot simpler than gitflow or other alternatives. I have 1-2 "pull request" branches that I constantly reuse.
The principal assumptions are:
- There is a single long-lived branch, typically called
main
ormaster
- Pull requests made from a short-lived branch that is deleted after the PR is merged
- PRs are merged via "squashing" into a single commit
- Therefore, no one cares what your branch is called since there's never many branches open
If this doesn't describe your workflow, you're not going to like this.
TL;DR — run git rebranch
when you start a new feature. It recreates the current branch on top of origin/main
.
sequenceDiagram
participant main
participant tim-pr
participant Github
rect rgb(50, 50, 120)
note right of main: git-rebranch
tim-pr->>Github: Check for PRs <br/>open on tim-pr
tim-pr->>tim-pr: git branch -D
tim-pr->>main: git checkout
Github->>main: git pull
main->>tim-pr: git checkout -b
end
tim-pr->>tim-pr: Do Work
tim-pr->>Github: git push
Github->>Github: Create Pull Request
Github->>main: Merge tim-pr into main
Github->>tim-pr: Delete tim-pr
I call mine tim-pr
so it's abundantly clear what it does. Its a branch that I, Tim, use for pull requests.
Generally, having multiple branches open is a smell that means you have a lot of work in progress. But whatever, if you
really want to, just create a new branch called tim-pr-2
or whatever makes sense, and run git rebranch
.
In a previous version of this script it would delete my local branch and I'd eventually figure out that I messed things up
when I went to createa a pull request. Now, in the current version, it uses the Github CLI to check if there's a branch open.
It definitely saves a lot of headaches. If rejected, I just create a new branch and run git rebranch
again.
Awesome. It's awesome. I wrote this in oil shell so I could try it out, and it's great. The idea is to have a shell language that looks more like Python or JavaScript.