8 ms·
I use: git init --bare $HOME/.myconf alias config='/usr/bin/git --git-dir=$HOME/.myconf/ --work-tree=$HOME' config config status.showUntrackedFiles
by StreakyCobra 11y ago
I use:
git init --bare $HOME/.myconf
alias config='/usr/bin/git --git-dir=$HOME/.myconf/ --work-tree=$HOME'
config config status.showUntrackedFiles no
where my ~/.myconf directory is a git bare repository. Then any file within the home folder can be versioned with normal commands like:
config status
config add .vimrc
config commit -m "Add vimrc"
config add .config/redshift.conf
config commit -m "Add redshift config"
config push
And so one…
No extra tooling, no symlinks, files are tracked on a version control system, you can use different branches for different computers, you can replicate you configuration easily on new installation.
- durdn 11y agoHonestly this is genius! I hadn't thought of doing it like that, thank you! I had resorted to the usual .cfg folder and a helper script to link/update everything.
- shabda 11y agoCould you explain how this works? Won't this be putting the .bashrc in $HOME/.myconf/.bashrc, which won't get picked up by bash? (And similar for other dotfiles)
- nindalf 11y agoYou could add a symlink in your $HOME folder
- unwind 11y agoNo, since the config alias runs git with the option "--work-tree=$HOME", which tells it that the working directory is your home directory root, i.e. where config files (used to) live. Anyway it's the proper root for config files, since if you use a .config directory (as seems to be the modern choice) that needs to live in your home directory of course.
- seliopou 11y agoTo complete the description of the workflow (for others), you can replicate your home directory on a new machine using the following command: git clone --separate-git-dir=~/.myconf /path/to/repo ~ This is the best solution I've seen so far, and I may adopt it next time I get the itch to reconfigure my environment.
- telotortium 11y agoFor posterity, note that this will fail if your home directory isn't empty. To get around that, clone the repo's working directory into a temporary directory first and then delete that directory, git clone --separate-git-dir=$HOME/.myconf /path/to/repo $HOME/myconf-tmp cp ~/myconf-tmp/.gitmodules ~ # If you use Git submodules rm -r ~/myconf-tmp/ alias config='/usr/bin/git --git-dir=$HOME/.myconf/ --work-tree=$HOME' and then proceed as before.
- durdn 11y agoI found out exactly the same problem :)
- aprdm 11y agoCan you write a blog post on your workflow? I would love to learn more on how you to use it :P
- durdn 11y agoI'm trying to reproduce it and documenting it as I go... ok I got it working now and I have notes. Stay tuned.
- StreakyCobra 11y agoIt's probably better if you do it then :-) I would probably skip some important parts trying to explain because I'm too much used to it already.
- durdn 11y agoWorking on it! I'll give you full credit for it and link to this thread for reference. Also let me know if you have a Twitter account you'd like me to reference.
- StreakyCobra 11y agoNice thanks. I don't have twitter. Also don't present me as the inventor of this technique because I'm not. I've read this long time ago on some dark corners of the internet :-) I'm just pointing it out.
- durdn 11y agoAlright I'll be careful in my wording ;).
- Siilwyn 11y agoFinally got mine working, it does need some figuring out especially the replication part. I documented the needed commands here: https://github.com/Siilwyn/my-dotfiles/tree/master/.my-dotfiles https://github.com/Siilwyn/my-dotfiles/tree/master/.my-dotfi...
- abricot 11y agoI'm confused - you can add files that are in a parent directory?
- StreakyCobra 11y agoIt's because we specify to git that the working tree is the home folder. For it the versionning doesn't happen in ".myconf", but directly in the home folder
- qznc 11y ago"branches for different computers" sounds tedious if most changes are for every computer.
- StreakyCobra 11y agoI have a "master" branch, and some "computer" branches. When changes are required for all computer, I do it in "master", and then update each branch by doing a "git merge master".
- wooptoo 11y agoWhy is this a bare repo as opposed to a normal one?
- StreakyCobra 11y agoBecause the working tree is already your home folder, you don't need to also have a copy of these files in ".myconf/".
- idle_zealot 11y agoSo why use .myconf/ at all? What is it doing?
- telotortium 11y agoIt contains the files that would normally be in .git (run `git help gitrepository-layout` for more details on the contents).
- deleted 11y ago[deleted]
- kavehmz 11y agoYou mean, you are also adding pushing your .ssh dir to a remote repo?
- durdn 11y agoNot at all. You can 'git add' (or in the case of the technique above 'config add') only the files and folders that are safely stored in a repository. Because of the 'ShowUntrackedFiles' flag, git/config won't always show folders you don't want to track, which would be annoying.
- kavehmz 11y agoPerfect then,
- durdn 11y agoAs promised I wrote a post about your setup. Thanks a lot for bringing the technique to my attention: https://developer.atlassian.com/blog/2016/02/best-way-to-store-dotfiles-git-bare-repo/ https://developer.atlassian.com/blog/2016/02/best-way-to-sto...
- StreakyCobra 11y agoReally nice, well explained. I'll know where to point people to when I need to present this techique. Thanks!