My question is.
Why can't we just "git" the entire .config directory? Wouldn't that be a simpler way to manage dotfiles? for e.g. My ".config directory" is about 250 mb which is well below the space limit in Gitlab/hub. Ofcoruse I will keep it private.
What are edge cases? I issue I can think of is that it might generate a lot of Untracked files when you run git. Idk. I am just a noob thinking aloud.
I have checked out several soltions to solving the problem of managing dot files. Top of them include
- Create --bare git repository and create custom git commands
- Save preferred dotfiles in another respository like Documents and git it
- create symlink to the Dotfiles you need and manage them from @HOME with git
- Use Stow or yadm ( yet another dotfiles manager)
[Managing dotfiles] (https://www.atlassian.com/git/tutorials/dotfiles)
Why you Shouldn't:
The problem with dotfiles is their lack of standardization. While usually they store things like
my username is billy4, sometimes dotfiles can have authentication information, binaries, cache, temporary files, state data, etc. that you don't want to go to source control.For example,
.npmrchas (at least mine does, I can't say the same for everyone) registration tokensshpotify's.shpotifyrcfile has auth tokens, the~/.config/gh,~/.config/configstore/firebase-tools.jsonfolder can have logins -- you get the point.As well, applications sometimes store all of their app data in the config folder, like iTerm2.
~/.config/iterm2stores all of your settings, cached data, the iTerm window state, shell history, etc..I can't recall if this is default or not, but I have my environment setup so that my global
.yarnrcis in my config folderFinally, applications can store log/history files there, and if they were checked into source control, while it's not the end of the world, it would make things difficult to maintain and add a lot of complexity. You wouldn't want to check
.zsh_historyor something similar to source control right? That'd make the repo an extreme pain to push, pull or merge.Workaround:
This is a solution similar to my dotfile repository (You're probably not interested in what my terminal looks like or what font I use, but it might help you with your solution's file structure and potential setup scripts).
TLDR; you can move the children (that you want in source control) of .config to a different path like
~/.dotfiles, then create a git repo in it, and link each one to~/.config.If I were you, I'd put all of the config files that I want in git in a path like
~/.dotfiles, I'd link all of the children (except one) of the~/.dotfilessource to be in~. For example:~/.dotfiles/.zshrcwould be linked to~/.zshrc. The child not to link is~/.dotfiles/.config. This is because I would runmkdir -p ~/.config(in case it isn't already), then I'd link every child directory of~/.dotfiles/.config/<child>to~/.config/<child>. This allows me to put whatever config folder I want in the repo's.configfolder to be sent to~/.config, but I could also have items in~/.configthat are normal folders instead of links.Here is kind of what I mean:
There are upsides and downsides to both.
Linking the whole folder gives a lot less control and you will likely have things you don't want to be in your repo. However, it also is a lot simpler, and easier to manage. If I modify any child or grandchild (etc.) of
~/.some-folderfrom either side (source file vs. link), all of the changes will be reflected. I can update, delete, create, etc.If you are more specific with your linking (linking children, childrens' children, etc.), you can have more control with what goes to git, and what stays local. By making
~/.configan actual folder, and linking each child to it, I can decide I don't want~/.config/.authto go to the repo and just put it in the~/.config/.authdirectory. this all works because~/.configis a normal folder, it isn't a symlink, and if you put something in it, there won't be any changes in~/.dotfiles/.config.Getting too specific with links can make things pretty challenging to manage; let's say, for example, instead of linking the whole
.config/gitfolder, I link.config/git/configand.config/git/aliases. Later, if I decide to add.config/git/some-other-file, I need to create it in the dotfiles source, then link it. If I rename.config/git/configto.config/git/gitconfig, I need to delete the.config/git/configlink (it will be pointing to a file that doesn't exist), and add a link for.config/git/gitconfig.I thought quite a bit about this when I set up my repo, and once you get the right balance of ease and specificity, it is super nice.
I'd recommend making a bash file that will read the contents of the
~/.dotfilesdirectory and set up the links, so that if you want to update your dotfiles because of a name change, deletion, etc., you can just run something like:~/.dotfiles/link.shand it will update the links for you.