Hacker News new | past | comments | ask | show | jobs | submit login

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.




To 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.


For 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.


I found out exactly the same problem :)


As 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-sto...


Really nice, well explained. I'll know where to point people to when I need to present this techique. Thanks!


Can you write a blog post on your workflow? I would love to learn more on how you to use it :P


There are probably already posts about this: I didn't invented it, I read it somewhere… but it was long time ago, I don't remember where.


I'm trying to reproduce it and documenting it as I go... ok I got it working now and I have notes. Stay tuned.


It'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.


Finally 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-dotfi...


I'll check how you did it. I wrote my notes and a couple of scripts down in a post: https://developer.atlassian.com/blog/2016/02/best-way-to-sto...


Working 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.


Nice 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.


Alright I'll be careful in my wording ;).


Why is this a bare repo as opposed to a normal one?


Because the working tree is already your home folder, you don't need to also have a copy of these files in ".myconf/".


So why use .myconf/ at all? What is it doing?


It contains the files that would normally be in .git (run `git help gitrepository-layout` for more details on the contents).


Honestly 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.


Could 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)


No, 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.


You could add a symlink in your $HOME folder


"branches for different computers" sounds tedious if most changes are for every computer.


I 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".


You mean, you are also adding pushing your .ssh dir to a remote repo?


Not 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.


Perfect then,


I'm confused - you can add files that are in a parent directory?


It'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




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: