5 Unusual Ways to Use Git

gitgithubgithub actions

A few days ago, I got recommended a video titled Using docker in unusual ways on YouTube.

In the video, he talks about some useful ways of using Docker, like using it to support legacy apps, for making testing simpler and more robust, and as a development environment. To me, the title felt quite misleading. Most of these use cases are not really "unusual", we actually see them being used in a lot of organizations. Containerized testing has become the norm because it's cost-effective in the cloud and simpler to maintain after the initial setup overhead. VS Code Dev Containers is a popular way to use Docker for having all the dependencies automatically set up as soon as you open your editor.

This video also gave me an idea. I use Git a lot everyday. That doesn't sound unusual for a developer, but one could say I use Git an obsessive amount. Some of those ways are not what Git was designed to do, but it happened to be good enough at it that I chose to use it over a more dedicated solution. Having one interface to work with several things also incurs less mental overhead.

So I wrote this article to talk about five such ways I use Git, that normal people would find "unusual":

Tamper-proofing personal files and secrets

I track all my personal files with Git. This allows me to prevent file tampering, because if the file changes, Git will identify it. I admit that this is a very niche thing to worry about, with most personal files being images and PDF documents. I still prefer being able to track every "change" made to my personal files with descriptive commits. It is a chore that is hard to get into without a serious passion (and a hint of paranoia).

I use VS Code to edit my secrets and encrypt them with GnuPG, made possible by my own VS Code extension DCrypt. The extension is not as mature as something like SOPS, and with me being its sole lazy maintainer, it will probably never be. So it lacks some nice features like change detection, where SOPS does not write to the cipher file if no changes were made to the secrets. This is a problem for me. I may accidentally type something into the editor, and that would cause the file to change due to VS Code auto-save, and since the secrets are mostly random characters, it makes it much harder to visually identify tampering. So, I simply track the secrets with Git too. I initially got the idea from Pass, which is backed by a local Git repo to manage secrets. I also learned to track secrets separately from my personal folders, simply because it makes it easier to prune old changes by just dropping the commits past a certain date.

Using Git branches to separate common configs and scripts

I write scripts for automation of day-to-day tasks. It makes it easier to manage my time and ensure consistency in my work. I do this for both personal tasks and work tasks. There are some scripts that I use in personal tasks, that don't make sense at work, and vice versa. But there are some scripts that are useful both in personal tasks and work tasks, like a script to list reachable IPs and host names in a network. So I maintain a separate branch called common and I ensure the common branch of my personal automation repo stays in sync with the common branch of my work repo. This makes it easier to port common useful scripts so they can be available for both personal tasks and work tasks when needed.

Same goes for configs. If I use the same applications at both home and work, chances are there will be some configs that I prefer to keep consistent across both machines. But there is also a nicety that comes with using Git for this instead of something else. It's possible for me to only track parts of the config file in common, meanwhile configs that are confidential or local to the machine can be removed from tracking.

Version-controlling patches

This is another one of those niche use cases that few actually need, and for those that need it, there are probably better alternatives. When working with code, sometimes there will be changes that you never wanna actually check in, but you need them for future. Like when you make a local change in the code to add some debug logs, that are verbose or expose sensitive details and hence, too dangerous to check in, but you do want to keep them for future debugging purpose. And maybe you also want to maintain different snapshots of such patches, so that you can fall back as the code changes and you need logging to change with it, but you also may need older versions of logging to debug older versions of code.

A less crazy alternative for this is to push such commits to a separate branch in your fork, but never make a PR for it.

Using a Git hosting platform's workflows to export assets for different versions

The best example for this use case is documents written with markup languages like Markdown, LaTeX, and Typst. Almost always you end up requiring to export them into more legible formats like PDF or PNG. Manually exporting with every new version of the source or grouping the exports with their source versions is a pain. This is where workflows come in.

When I was applying for work, I used LaTeX (currently switched to Typst) to write my resume. To tailor resumes to different recruiters, I needed to maintain branches where each branch highlighted different set of my skills relevant to the job description. Using Git on LaTeX helped here, but I also needed a way to track the exported PDFs to ensure I accidentally didn't send the wrong type of resume for the job description. So I used GitHub Actions and an action that automatically exported the PDF and made a release for it, so I can always check releases to find the right version of the resume.

Using a Git hosting platform for project collaboration

When I was working on group projects in college, I needed a way to maintain a shared workspace for the project where my team members can view and work on project artifacts and resources. We initially used a shared Dropbox folder, but that soon became tedious as it was as bad as OneDrive at handling file sync conflicts and used to create different versions when conflicts arose.

What better way to maintain a shared workspace than a platform designed to provide an interface for conflict resolution? So we started maintaining a private repo on GitHub to manage project source code, documentation, presentations and papers. It wasn't as bad as we thought, as it allowed us to only commit edits after we were confident in them, instead of files being synced on every save, which were choking Dropbox.

We did face some issues with Office files like Word and PowerPoint, but in those cases we just pulled the changes, copied the changes manually on top of the most recent version of the file. It wasn't as simple as a shared Google doc, but thanks to Git enforcing commits for pushing changes, we mostly only pushed huge changesets anyway, so the total number of conflicts decreased.

This concludes my list of unusual ways to use Git. If you like it, or if you have your own share of stories, let me know via email!