Linux Config to Git - Streamlining my workflow - part 1

Intro

Have you ever experienced the sinking feeling of losing your meticulously crafted Linux workspace? Whether it's a hardware failure, a new job, or simply a fresh machine, setting up your environment from scratch is a daunting task. I've spent countless hours painstakingly recreating my ideal setup, only to find lingering inconsistencies. To combat this, I'm embarking on a journey to version control my Linux configuration using Git. This series will document my progress, sharing tips and tricks along the way.

Target

The goal is to create a portable, version-controlled Linux environment that can be quickly replicated on any machine. By leveraging Git, I aim to minimize the frustration of setting up a new workspace.

Key Principles

  • Git as the Central Repository: Anything that can be comfortably stored in Git will be included.

  • Incremental Approach: Starting with .zshrc and gradually expanding to other configuration files.

  • Security First: Only non-sensitive data will be committed to the repository.

  • Automation with Makefiles: Using Makefiles to ensure configuration files are consistently updated.

  • Continuous Improvement: This series will evolve as new ideas and challenges arise.

Start from Setting Up the Git Repository:

I began by creating a new repository on GitHub (tutaj dodaj link). Then, I cloned it locally and started adding the essential files.

  • I created a terminal folder to house my .zshrc and shell.pre-oh-my-zsh files. Initially, these files were empty.

  • Next, I created a Makefile in the root directory.

Makefile

ZSHRC_SOURCE := ~/.zshrc
ZSHRC_TARGET := ./terminal/.zshrc

SHELL_PRE_OH_MY_ZSH_SOURCE := ~/.shell.pre-oh-my-zsh
SHELL_PRE_OH_MY_ZSH_TARGET := ./terminal/shell.pre-oh-my-zsh

.PHONY: all update-zshrc update-shell-pre-oh-my-zsh

all: update-zshrc update-shell-pre-oh-my-zsh

$(ZSHRC_TARGET): $(ZSHRC_SOURCE)
        cp $(ZSHRC_SOURCE) $(ZSHRC_TARGET)
        @echo "Updated .zshrc in project folder."

$(SHELL_PRE_OH_MY_ZSH_TARGET): $(SHELL_PRE_OH_MY_ZSH_SOURCE)
        cp $(SHELL_PRE_OH_MY_ZSH_SOURCE) $(SHELL_PRE_OH_MY_ZSH_TARGET)
        @echo "Updated shell.pre-oh-my-zsh in project folder."

What does the Makefile do

This Makefile automates the process of copying your current .zshrc and shell.pre-oh-my-zsh configuration files into the project's terminal directory. Here's a breakdown:

  • Variables: ZSHRC_SOURCE, ZSHRC_TARGET, SHELL_PRE_OH_MY_ZSH_SOURCE, and SHELL_PRE_OH_MY_ZSH_TARGET define the paths to your configuration files.

  • .PHONY: Declares all, update-zshrc, and update-shell-pre-oh-my-zsh as phony targets, meaning they don't correspond to actual files.

  • all: This target, when executed, runs both update-zshrc and update-shell-pre-oh-my-zsh.

  • update-zshrc and update-shell-pre-oh-my-zsh: These targets use the cp command to copy the configuration files from your home directory to the project's terminal directory. The @echo command provides feedback on the update process.

Updating Files in the Repository

To update all files, simply run make in the root directory. To update a specific file, use make update-zshrc or make update-shell-pre-oh-my-zsh.

Troubleshooting

If make doesn't seem to do anything, it might be because the files in the repository are newer than your local configuration files. In that case, use touch ~/.zshrc and touch ~/.shell.pre-oh-my-zsh to update the timestamps of your local files. Then, run make again.

Next Steps

In the upcoming parts of this series, I'll be:

  • Adding more configuration files and frequently used shell scripts.

  • Creating a script and alias to run make all from any terminal location and automatically create a pull request with the changes.

Stay tuned for more updates on my journey to a fully version-controlled Linux workspace!

0
Subscribe to my newsletter

Read articles from Przemysław Kozłowski directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Przemysław Kozłowski
Przemysław Kozłowski

I'm a software developer with over 10 years of experience in the IT industry. I began my career as a C# developer and, after a few years, had the opportunity to explore Node.js. That experience completely captivated me, and I decided to shift my focus toward JavaScript and backend development with Node.js — though I’ve continued to contribute to a long-term C# side project as well. In the past two years, I’ve also ventured into the world of DevOps. It was a completely new area for me, and I started from scratch. It's been an exciting challenge — since then, every day has been filled with learning and new experiences. This journey inspired me to document my progress and reflections by starting this blog as a learning journal. Currently, I'm particularly focused on improving my understanding of networking — an area I’ve always found challenging — as well as deepening my skills in Docker and Ansible. I’m also planning to set up a Kubernetes cluster in my home lab to begin learning container orchestration hands-on. Additionally, I’ve started learning Python, which I see as a powerful tool for automation and scripting in the DevOps toolkit. The purpose of this blog is to document my learning journey and track my progress, but also to share knowledge and support others who are just beginning their DevOps path and considering a career transition into this field. Outside of tech, I'm a happy father of two boys. I've managed to pass on my love for retro games, swimming and cycling to them. I dedicate most of my free time to being with them — and when I do have a moment to myself, I usually spend it on my road bike.