top of page
christiandreschler9

Managing dotfiles with a git bare repository - Part 2

Updated: Nov 26

Disclaimer: there are other proven solutions to the problem. I do think the technique below is very elegant though.



Recap of Part 1?

In Part 1 we created a git bare repository and we learnt how to interact with it, by adding, committing and pushing all the changes.


You can find Part 1 here.


Now we're going to manage the dotfiles online using gitlab.com (any other git related server is fine too).


For the sole purpose of this guide, I will use gitlab.com


Managing dotfiles online


Pre-requisites:

  1. You should register an account on gitlab.com, it's free.

    Any other git server is fine too.

    If you already have an account you can skip this step.


  2. You should have followed all the steps listed in Part 1 here.


Pushing the dotfiles to the git server:

Push the existing dotfiles repo on the server by typing the following commands in the terminal.

cd ~/dots

config remote add origin https://www.gitlab.com/UserName/dots

config push origin main

Where:

  1. The first line will open the folder of your local git bare repo.


  2. The second line will add the repo web-address to the local repository configuration file.

    Warning:

    Replace "UserName" with your actual username.

    Make sure that both your username and remote server name are correct.


  3. The third line will push all the staged content of the git repository to the gitlab server online

    Note:

    The staged content in our case are all the files you have added to the local repository using the 'config add' command followed by the file name(s)


Installing dotfiles to another system

If you have just installed a new system, and you would like to get your dotfiles in the right path, you should type the following commands.


Warning:

A pre-requisite is the installation of git, if it's not installed yet.

echo 'alias config="/usr/bin/git --git-dir=$HOME/dots --work-tree=$HOME"' >> $HOME/.bashrc

source ~/.bashrc

echo "dots" >> .gitignore

git clone --bare https://www.gitlab.com/UserName/dots $HOME/dots

config checkout

config config --local status.showUntrackedFiles no

Where:

  1. The first line creates an alias to ensure that the git bare repository works without problem.

    (It assumes you're using the bash shell, if not redirect it to the shell config file you use)


  2. The second line reloads the shell config file to use that alias.


  3. The third line adds the 'dots' directory to the '.gitignore' file to prevent recursion issues.


  4. The fourth line clones the remote repo using the '--bare' flag (it's a git bare repo after all).

    Warning:

    Replace "UserName" with your actual username.

    Make sure that both your username and remote server name are correct.


  5. The fifth line performs the checkout, so all the dotfiles will be placed in the correct path.

    Warning:

    1. ff you already have configuration files with identical names, checkout will fail.

    2. Back up and remove those files. Skip back up if you don’t need them.


  6. The sixth line prevents untracked files from showing up at the 'config status' command.


Few words on your privacy

Don't add to the repo files that may contain your gpg keys or passwords.


Remember that all the dotfiles will be uploaded on an online server and even if the repo is private, it contains sensitive information, so be careful on what you upload.


Conclusion

In the part 2 I showed you how to push the git bare repository on a git server online and how to install the dotfiles on a brand new system installation.


What's next?

It's only up to you and your creativity.


To expand your knowledge and expertise you can also try to automate all the above tasks using a bash script that will install your system and pull all the app and system configuration files (dotfiles) from an online server.


Using this solution you can install a Linux distribution and have it already configured in less than twenty minutes.


With Arch and arch-based distros this process is rather easy.

With other distros the result may change.


Don't do it on your bare-metal hardware!

Try this first on a virtual machine (VirtualBox, Gnome-Boxes, Virt-Manager etc)





6 views0 comments

Recent Posts

See All

Comments


bottom of page