Stupid Git Tricks

My apologies if you speak the Queen’s English since that title probably has a whole different meaning to you than I intended. In fact, I’m talking about Git, the version control system. Last time I talked about how the program came to be and offered you a few tutorials. If you are a dyed-in-the-wool software developer, you probably don’t need to be convinced to use Git. But even if you aren’t, there are a lot of things you can do with Git that don’t fit the usual mold.

Tracking Documents

Git is really good at tracking changes in documents. If you write plain text files, Markdown, or TeX files, you are in business. However, there is a trick you can use if you use Word, OpenOffice, or many other word processing programs. As a benefit, you’ll even be able to collaborate with others using different programs.

The trick, described in this post and this one, is to configure Git to use a program called Pandoc to convert your input files into Markdown. The Git program can store both, and you can explain to it that differences in the Markdown file correspond to the differences in the document file.

Pandoc is a tool worth knowing about anyway. It converts to and from a dizzying number of formats. If you want to give yourself a headache, you can expand the graphic from their site and try to trace all the lines.

We’ve seen this sort of thing work for collaborative textbooks and even used to track frequently changing documents like French legal codes going back to the time of Napoleon.

Working on a Web Site

You can easily extend the idea of tracking documents to tracking HTML pages for your website. You could just use it as you create and then upload your files like normal. You can also use specialized workflows. Even if you are the sole creator of the site, being able to rewind to what the site looked like last week or last month is often unexpectedly useful.

Managing your Bash Profile or /etc

If you use Linux, you have a lot of files that configure your environment. Things like your .bashrc, .emacs, and so on are hard to keep the same if you use multiple machines. Sure, you can rsync them, but if they ever get messed up, it can be hard to go back and figure out what happened. That’s why I wrote a system for managing this problem using Git. Once it is configured, your machines will automatically pick up any changes you push to the remote host (I keep mine on GitLab). The system is flexible enough to allow for custom configuration per machine and even keep random files in sync for you with just a little setup.

There’s a similar package called etckeeper for keeping track of your system-wide configuration in the /etc directory. You could argue that configuration files are essentially just code, but the intent isn’t coding but keeping version control and synchronization between machines. Also, in the case of etckeeper, there are modifications so Git will store some metadata that is important for that application.

Git as a Database or Bug Tracker

If you are using Git for development, it only makes sense you could use it for tracking bugs, too. In fact, you can use Git as a simple database. Don’t expect to run SQL queries — this just shows a name-value pair system (the proverbial NoSQL database).

Of course, you can store SQLite database (or anything else) in Git. If you do, you can play some tricks like the Pandoc trick for documents to help Git understand your databases better.

Twitter (Yes, Twitter)

Ever wanted a distributed Twitter implementation? Check out Madrox. We aren’t really sure why we want this, but we do.

Text-based Slideshows

Have you ever wanted to show a progression of text screens like a slideshow? Maybe not, but if you did, Git can do that, too. It needs a little help from vim, though.


Even if you never need any of these tricks, some of the methods used to coax Git into doing something unusual might spur you to think of something else. An obvious idea would be a difference program for Gerbers or some other printed circuit board file format. Being able to see what changed between a few revisions of a PC board would be really useful. Obviously, being able to track schematics would be useful, too. Spice models ought to be no problem at all.

Have any useful Git hacks? Leave a link in the comments.

Lattice iCE40 FPGA Configured by Linux Kernel

The Linux kernel recently added support for loading firmware into an FPGA via the FPGA Manager Framework. [OpenTechLab] has built a driver for the Lattice iCE40 FPGA (same chip used on the iCEStick and other development boards). One attraction to the iCE40 is there is an open source toolchain called iCEStorm.

Even if you aren’t specifically interested in FPGAs, the discussion about Linux device drivers is good background. The principles would apply to other drivers, and would definitely apply if you want to write another FPGA loader.

Continue reading “Lattice iCE40 FPGA Configured by Linux Kernel”

Linux-Fu: Applications on the Web

Did you know you can run remote Linux GUI programs in a browser with HTML5 support? It’s even secure because you can use SSH tunneling and that little trick means you don’t even need to open additional ports. If this sounds like gibberish, read on, it’s actually pretty easy to get up and running.

I recently was a guest on a Houston-based podcast, and the hosts asked me if the best thing about writing for Hackaday was getting to work with the other Hackaday staff. I told them that was really good, but what I like best was interacting with people (well, most people) in the comments. That sometimes you’d post an article and someone would bring a topic up in comments that would really knock your socks off. This is how I wound up with this nearly ideal remote access solution, that requires nothing on the remote side but a web browser.

A while back I posted about keeping programs running after log off on a Linux box. The post was mostly about non-GUI programs but you could use NX or VNC to handle it. In the comments, someone mentioned how unhappy they’d been with recent copies of NX and another commenter called [Screen for X11] posted about a tool called xpra.

Continue reading “Linux-Fu: Applications on the Web”

Lint for Shell Scripters

It used to be one of the joys of writing embedded software was never having to deploy shell scripts. But now with platforms like the Raspberry Pi becoming very common, Linux shell scripts can be a big part of a system–even the whole system, in some cases. How do you know your shell script is error-free before you deploy it? Of course, nothing can catch all errors, but you might try ShellCheck.

When you compile a C program, the compiler usually catches most of your gross errors. The shell, though, doesn’t look at everything until it runs which means you might have an error just waiting for the right path of an if statement or the wrong file name to occur. ShellCheck can help you identify those issues before deployment.

If you don’t like pasting your script into a Web page, you can install the checker locally by visiting GitHub. The readme file there also explains what kind of things the tool can catch. It can even integrate with common editors (as seen in the video below).

Continue reading “Lint for Shell Scripters”

Swan: Better Linux on Windows

If you are a Linux user that has to use Windows — or even a Windows user that needs some Linux support — Cygwin has long been a great tool for getting things done. It provides a nearly complete Linux toolset. It also provides almost the entire Linux API, so that anything it doesn’t supply can probably be built from source. You can even write code on Windows, compile and test it and (usually) port it over to Linux painlessly.

However, Cygwin’s package management is a little clunky and setting up the GUI environment has always been tricky, especially for new users. A project called Swan aims to make a full-featured X11 Linux environment easy to install on Windows.

The project uses Cygwin along with Xfce for its desktop. Cygwin provides pretty good Windows integration, but Swan also includes extra features. For example, you can make your default browser the Windows browser with a single click. It also includes spm — a package manager for Cygwin that is somewhat easier to use, although it still launches the default package manager to do the work (this isn’t a new idea, by the way).

Continue reading “Swan: Better Linux on Windows”

Flashing An ARM With No Soldering

[Sami Pietikäinen] was working on an embedded Linux device based on an Atmel SAMA5D3x ARM-A5 processor. Normally, embedded Linux boxes will boot up off of flash memory or an SD card. But if you’re messing around, or just want to sidestep normal operation for any reason, you could conceivably want to bypass the normal boot procedure. Digging around in the chip’s datasheet, there’s a way to enter boot mode by soldering a wire to pull the BMS pin. As [Sami] demonstrates, there’s also a software way in, and it makes use of mmap, a ridiculously powerful Linux function that you should know about.

Continue reading “Flashing An ARM With No Soldering”

Linux-Fu: Keeping Things Running

If you’ve used Linux from the early days (or, like me, started with Unix), you didn’t have to learn as much right away and as things have become more complex, you can kind of pick things up as you go. If you are only starting with Linux because you are using a Raspberry Pi, became unhappy with XP being orphaned, or you are running a cloud server for your latest Skynet-like IoT project, it can be daunting to pick it all up in one place.

Recently my son asked me how do you make something run on a Linux box even after you log off. I thought that was a pretty good question and not necessarily a simple answer, depending on what you want to accomplish.

There’s really four different cases I could think of:

  1. You want to launch something you know will take a long time.
  2. You run something, realize it is going to take a long time, and want to log off without stopping it.
  3. You want to write a script or other kind of program that detaches itself and keeps running (known as a daemon).
  4. You want some program to run all the time, even if you didn’t log in after a reboot.

Continue reading “Linux-Fu: Keeping Things Running”