5

I'd like to put all my dotfiles (like .profile, .gitconfig, etc.) in a central git repository, so I can more easily keep track of the changes. I did this, but I would like to know how to properly handle keeping them in sync with the actual ones in ~/. I thought that you could just hard link the two using ln, but this does not seem to work as I expected, i.e., if I edit one file, the other does not change. Maybe I misused the ln command, or else I misunderstand how hard links work.

How do people usually do this? Judging by GitHub, it's a pretty popular thing to do, so surely there's a seamless way to do it that someone has come up with.

By the way, I'm on Mac OS X 10.6.

6

Many OS X programs, such as TextEdit, save files in a way that breaks hard links.

At least on Linux, symlinks are usually used for this purpose:

$ ln -s ~/dotfiles/bashrc ~/.bashrc
5
  • OK. I've been using TextWrangler to edit the files, so maybe it is screwing them up. I'll try symlinks and see if they work.
    – asmeurer
    Jun 28 '11 at 3:33
  • I tried symlinking my .profile file, but source ~/.profile gave -bash: /Users/aaronmeurer/.profile: Too many levels of symbolic links.
    – asmeurer
    Jun 28 '11 at 3:45
  • 1
    @asmeurer: You symlinked it to itself. (Remember that link targets are relative to the link itself, not to your current directory.)
    – user1686
    Jun 28 '11 at 9:10
  • I see. It's essential to give absolute paths as arguments to ln. It works when I do that.
    – asmeurer
    Jul 10 '11 at 2:31
  • @asmeurer: Not necessarily. ln -s dotfiles/bashrc ~/.bashrc would work as well, as long as you remember that it's relative to ~/.
    – user1686
    Jul 10 '11 at 9:29
2

I've been helping build a tool to handle this called freshshell. It's similar to homesick with the added feature of being able to pull in files from any GitHub repository, the idea being that you can grab pieces of other peoples config along side your own.

fresh is a tool to source shell configuration (aliases, functions, etc) from others into your own configuration files. We also support files such as ackrc and gitconfig. Think of it as Bundler for your dot files.

2

I highly recommend vcsh and myrepos to manage your dotfiles via Git (and across multiple machines).

Richard Hartmann’s vcsh allows you to manage all your dotfiles in Git without the need to set up numerous symlinks. The key is that any number of Git repositories can co-exist in parallel in your home directory without getting in each other’s way. Furthermore, vcsh was designed with myrepos in mind. This tool allows you to manage all your version control repositories all at once. Most notably, mr can update all your repositories with one single call. Ideal for setting up all your dotfiles on a new machine with as little effort as possible.

I just published a blog entry that explains how to set up these tools in order that you are able to manage dotfiles quickly and effortlessly. Maybe this is helpful for you.

1

There is a rubygem: homesick which solves all of this! it supports github out of the box and will symlink everything for you.

protip: if you add changes to the dotfiles you'll still need to clone the repos in a seperate dir, make changes from and there push. then pull them with homesick.

additional if you're using VIM?:

use pathogen because it works really well when managing dotfiles in git. Plugins can be added as submodules and will load effortless.

1

There are many ways to achieve painless dotfiles management, like one most popular I have seen is creating a git repository and symlinking the dotfiles, while this solutions works for storing but is it completely painless? No!, you still need to do some configurations after cloning the git reposistory.

The thing about CS is that We can always do better, and with saying that, there exists a much more elegenet solution with only uses git. The trick here is to create a bare repository instead of normal.

  1. create a bare repository in your home directory by doing git init --bare $HOME/.dotfiles
  2. create an alias with the name dotfiles in your .zshrc for convenience
alias dotfiles='/usr/bin/git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME
  1. there you can use it like normal git repository to add, commit and push.
# to check the status of the tracked and untracked files 
dotfiles status

# to add a file 
dotfiles commit .tmux.conf -m ".tmux.conf added"

# push new files or changes to the github
dotfiles push origin main

Read more about this + how to automate installation of apps and libs - https://github.com/kalkayan/dotfiles

0

Since making this question, I've been maintaining my dotfiles in a git repo for a while. I use a custom script that I wrote that automatically symlinks all the files in the repo, ignoring any file in an IGNORE file. The script is here. It is licensed MIT, so feel free to reuse it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.