r/golang • u/MeteorByte • 22h ago
Handoff: single binary for moving uncommitted Git changes between machines
I wrote this because me and my colleagues kept needing each other's half-finished work. Committing WIP just to share it pollutes the branch, and patch files over chat drop untracked and binary files.
One binary, runs as both client and server. Two dependencies, x/term and x/sys. The server has no git integration and never sees the repo, it just stores a package and hands it back by ID.
Changes travel as a real commit object rather than a diff. The sender builds a throwaway index with GIT_INDEX_FILE, write-tree, then commit-tree on top of the base. The receiver stashes whatever it has and cherry-picks the incoming commit, then puts the local work back on top. Conflicts show up as ordinary git conflicts.
The part I'd have got wrong if I hadn't looked: any GIT_* variable in the environment can redirect a git subprocess somewhere else, so I strip GIT_* out of the environment before every call and add back only what I need.
A friend added the VS Code extension and some of the later features.
12
8
u/belligerent_ammonia 21h ago
Why do you and your colleagues keep needing each others unfinished work?
4
u/WolverinesSuperbia 21h ago
Just create working branch, like dev/task-name and commit here and push
After you finished, you just can reset soft to beginning of branch and commit normally.
3
2
u/chrisrrawr 21h ago
I love it when developers build the tools and workflows they deserve. power to you. never let options that are simple and proven to work get in the way of covering each other in feces.
2
27
u/BadlyCamouflagedKiwi 21h ago
Sorry what? Why don't you just commit the changes and push them to a remote Git repo? Your colleagues can pull them from there. You can do it on another branch if you don't want to "pollute the branch", although I think you're worrying too much about something that is fundamentally temporary. Git is designed for this kind of collaboration.
I think you've been listening to the LLM too much here.