Using Version Control

In the event that you are a seasoned programmer, this may seem a little obvious to you, but for the beginners coming out of bootcamps and computer science programs, it needs to be stated: you need to version your configs.

A central argument of this chapter is that using a tiling window manager and in particular developing one from the meager defaults to something that works for you specifically, provides an avenue to teaching you to become a better programmer. Learning programming isn’t just about learning how best to write a for loop. It’s also learning the development process, so that, few years down the road you can start a job with an understanding of how to handle yourself when working with others.

Treat your window manager configuration the way you would any program under development. Use a version control system, use branches when introducing new features, maintain a stable master so that you have something to roll back to in the event that things go wrong.

Note

While you shouldn’t consider this a hard and fast rule, it’s is recommended that you also open source and share your configs on GitHub or the like. While this recommendation does partly stem from the politics of promoting free software, it also stems from the pragmatism of easily getting help and advice from others.

Benefits of Version Control

What is a version control system? Simplest explanation is to think of it as a meta-save. When you edit a file and save it, you write the state of that file to disk. When you commit those changes to a version control system, you snapshot the current state of the file for later reference.

It’s possible that you may never look back at the file in that meta-saved state again. But, it’s also possible that you may do something horrible to your config and need to roll the whole thing back to the last commit. Version control is how you do that.

Benefits in Tiling WM’s

In most cases and specifically in five of the six cases covered here, the configuration file for a tiling window manager is actually a program written in the specific extension language the WM uses. Most of the time this isn’t a fully functional program, as in it’s not something that you can use by itself, but it a program nonetheless. Meaning, all arguments for using version control systems for development also apply to using them for developing tiling WM configs.

Additionally, unlike many stacking WM’s running in desktop environments, because the tiling WM uses plain text rather than a binary blog, making it much easier to see exactly what changed between versions, which can help you in trouble shooting the problems later.

Using Git

You can find more in depth consideration of Git elsewhere, but for now here are a few basic procedures on setting up and managing a local Git repository to version control your configs.

Initialize Repository

Each tiling window manager looks for its configuration files in a different place. You’ll need to check the specific guides or documentation to determine what path it uses for these files. When you find it, navigate to the file and create a Git repository, (such as, with i3wm):

$ cd ~/.config/i3
$ git init
Initializing empty Git repository in /home/USERNAME/.config/i3/.git/

In the event that you are unsure if the current directory contains an initialized Git repository, there are two methods to determine if it’s there:

  • Run ls and see if the output includes .git/:

    $ ls -al ~/.config/i3
    total 20
    drwxrwxr-x.  3 USERNAME USERGROUP 4096 Apr 20 06:14 .
    drwx------. 56 USERNAME USERGROUp 4096 Apr 20 06:11 ..
    -rw-rw-r--.  1 USERNAME USERGROUP 3211 Apr 20 06:14 config
    drwxrwxr-x.  7 USERNAME USERGROUP 4096 Apr 20 06:12 .git
    
  • Alternatively, you can use the git command itself to tell you what you need:

    $ git status
    On branch master
    Initial commit
    Untracked files:
    (use "git add <file>..." to include in what will be committed)
       config
    nothing added to commit but untracked files present (use "git add" to track)
    

As you can see, while ls provides you with the basic fact that a Git repository exists in this directory, git status gives you information about the particular state of that repository, as what branch is on, files not included in the repo. It also tells you what files have been modified since the last commit and which are in staging for the next commit.

Note

In practice, the console highlights untracked and modified files in red, staged file in green. We currently don’t have a way to support this feature through syntax highlighting on the website.

Configuring Git

If this your first time using Git, you need to configure it for your user. You need to set a username, email address and default editor. If you plan to work with Git a lot, it helps to use global settings, so you don’t have to do it on every repo.

  • Set the user name:

    $ git config --global user.name "Fyodor Dostoevsky"
    
  • Set the user email:

    $ git config --global user.email "fyodor.dostoevsky@example.com"
    
  • Set the default editor for writing commit messages:

    $ git config --global core.editor vim
    

In the example, famous late Russian novelist Fyodor Dostoevsky joins Fedora Resources as a writer and developer and he uses vim as his preferred text editor, because that’s just the kind of guy he is. You can display the configurations for your current use by running the --list option.

$ git config --list
user.name=Fyodor Dostoevsky
user.email=fyodor.dostoevsky@example.com
core.editor=vim

Committing Changes

In order to snapshot the repository for a commit, you first need to stage files. To do so, use the git add command:

$ git add config

When you’ve added all the files you want, run the commit.

$ git commit -m "Updates to config."

In the event that you didn’t provide the -m option with the commit message, Git opens the default editor and instructs you to write a commit message. This is an important step as it makes it easier to find commits later.

Additionally, if you use GitHub, you can tie commits to issues through the commit message. For example,

$ git commit -m "Ref #234 Initial implementation of volume control."

Once you push this commit to GitHub, on the website under Issue 234, it adds a link to this commit so that anyone following the issue can see what you did.

< Prev Next >