💾 Archived View for missbanal.net › git-super captured on 2024-07-08 at 23:28:29. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2024-06-16)
-=-=-=-=-=-=-
Published the 2024-05-30 on Willow's site
Huya, I discovered today that the git workflow I've been using for years have a name. Some folks on the internet call this: The stacked diff workflow
The idea is to commit over the default branch. And to forget that branches have ever existed.
$ git rebase -i origin/main
Open your text editor for you to re-order, drop, reword the commits that are not upstream.
$ git pull --rebase origin main
Pull the applied commits. Will eventually move your own commits when they get upstreamed. (btw: you should probably make `--rebase` the default).
$ git push origin <commit>:refs/heads/<branch> [-f]
Create (or replace) the remote `<branch>` with the pushed `<commit>`.
This last one is the verbose version of `git-push`. It is really not difficult to work with, when you get used to it.
The main problem is that you have to remember which branch name you used, to update it…
For this, I wrote a simple POSIX Shell script named `git-super`. It will store the branch name in dedicated `git-notes` references.
You can pass it a `<commit>` reference, or it will use `HEAD` by default.
It can also be used in the middle of an interactive rebase
$ git rebase -i origin/main ... editor fires pick a679c8d makefile: improve logging exec git super pick 6b75321 docker-compose: fix service declaration pick fc9467e src: fix memory leaks
Here we re-ordered the commit `a679c8d` right after `origin/main`, and then git will execute `git super`. The script will prompt for the branch name, and will push for us. Next time we'll use super with this commit, the push will update the same remote branch.
(The first time, `git super` will prompt for the remote it should use while pushing. `origin` is the default value, but you might have to use your writable forge "fork")
Now we can just use `git super a679c8d` to update the same remote reference. We don't need to remember the branch name anymore.
The script can be found here:
If this post inspired you, feels free to leave a comment!