3

I've been using a git repo for managing my systems configs for a while now. I used the documentation on Digital Ocean tutorials here. Pretty much I have a remote repo on a server. Do a git clone of the repo. Then symbolic link the dot files and directories to the home directory. If I change a config file I just do a git push to the remote repo.

The issue I'm running into is that I need different version of some configs. For example, the .i3blocks config is different depending if I'm using my home workstation, my laptop, or my work machine. I'm not very familiar with git so I'm not sure how to deal with this. Any suggestions?

2 Answers 2

3

This is not really a git problem. Instead, you have to think about what type of config files you have, what options they provide to read in additional files and how they diverge for different systems.

As an example, for your ~/.bashrc, you can have a master file that reads in host specific configs with a source line.

DOTFILES=~/.dotfiles
source $DOTFILES/$HOSTNAME.bashrc 

With other programs that don't allow this kind of operation in their config syntax, you might need to actually have multiple files for your different systems in the repo and only link the appropriate file.

ln -s ~/.dotfiles/i3blocks.$HOSTNAME ~/.i3blocks 

You could even combine this with some scripts that builds the file from building blocks or with some templating mechanism and that gets triggered by a git hook.

3
  • I thought of keeping multiple versions of the same file for the different machines. I would prefer to not have update each file when I change a line in the file that is common for all machines though.
    – emilan
    Sep 20, 2016 at 23:07
  • git can't help you with that, unfortunately. This is not an easy problem to solve and the best way I found around this when I can't import subfiles like with .bashrc is indeed building the final file out of building blocks or templates. That's something git can help you with if you use hooks to automate this.
    – Sven
    Sep 20, 2016 at 23:48
  • Thanks a lot Sven. I will take a look at the method you suggested.
    – emilan
    Sep 21, 2016 at 11:53
0

I do something similar and I use different branches for different setups. That way when you're on a given machine, you can do git checkout config-laptop or git checkout config-htpc, etc., to grab the files you want.

Also, if you make changes to files in one branch that you want to propagate to others, you can merge them across branches. Using a tool like GitKraken even allows you to merge just the sections (hunks)--or even single lines--you want.

1
  • I'll have to mess around with this method also. You guys gave me some ideas. Thanks for the help.
    – emilan
    Sep 21, 2016 at 11:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .