You are not logged in.

#1 2009-06-10 16:51:07

Mogger
Member
From: Sweden
Registered: 2008-12-07
Posts: 153
Website

Use Git to manage dotfiles

:: Disclaimer
I found some topics about placing ~ under version control, but none of the threads were specifically about dotfiles.
I'm completely new to Git and version control in general.

:: Problem
I want to version control some configuration files (.bashrc, .vimrc etc.) in ~ using Git. My reasons for this are as follows:
- Easy to backup files and discard changes.
- Share and synchronize configuration files between computers. I want to allow local customizations, more on this later.

Sounds pretty reasonable? The question is, how do I accomplish this? I did a little research, hoping to find a good article that described everything. What I found was a lot of articles[0-5], each describing its own way of using Git for dotfiles.

:: Solution?
I want to find an easy and straightforward way, that still allows flexibility. After some reading, I've come to the following conclusions:
- Having one git repository directly in ~ isn't a good idea. It's better to have one repo for each group of related files (e.g. all vim configuration).
- Some put the files in ~/dotfiles/* and symlink them, often using a script. This sounds rather complicated to me.
- There are already some scripts to handle everything: git-home and git-home-history. However, these seem to handle the whole ~, not specific dotfiles.
- My plan is to have a master branch where the common configuration are stored, and one branch for each computer for local customizations. (I haven't worked with branches before, but this is a pretty good opportunity to learn how, right?).

I like the sound of detached worktrees[5], but while it doesn't use symbolic links, it requires custom tools (scripts/mr tool). Maybe it's easier to go with the symbolic linking approach?

> Which method do you like the most, and are there any common pitfalls to look out for?

-
[0] http://psung.blogspot.com/2007/11/versi … emote.html
[1] http://wiki.debian-community.org/planet … directory/
[2] http://www.silassewell.com/blog/2009/03 … nd-github/
[3] http://robescriva.com/2009/01/manage-yo … -with-git/
[4] http://mnemonikk.org/2009/03/23/finally … n-control/
[5] http://tensixtyone.com/perma/the-versio … -directory

Offline

#2 2009-06-10 17:07:59

litemotiv
Forum Fellow
Registered: 2008-08-01
Posts: 5,026

Re: Use Git to manage dotfiles

i think i would just make a single Master for ~, git-ignoring all non-dotfiles:

git help ignore

since there aren't that many dotfiles it isn't really useful to create separate branches. also, since you are always working in a particular branch, you would have to manually rebase them on Master every time (which is a lot of hassle).

Last edited by litemotiv (2009-06-10 17:12:48)


ᶘ ᵒᴥᵒᶅ

Offline

#3 2009-06-10 18:14:17

cinan
Member
From: Slovakia
Registered: 2008-07-04
Posts: 251
Website

Re: Use Git to manage dotfiles

I started with http://daniel.debian.net/documents/cheatpages/git.html http://www-cs-students.stanford.edu/~bl … index.html and http://www.kernel.org/pub/software/scm/ … orial.html.
Symlinks don't work with git how you'd expect (try and you'll see). I made new dir, called git. Then I hardlinked all config files. E.g.:
'ln ~/.vimrc ~/.bahshrc ~/.xinitc ~/git'. And I'm happy smile

Last edited by cinan (2009-06-10 18:14:46)

Offline

#4 2009-06-10 20:41:47

stabele
Member
Registered: 2008-12-22
Posts: 101

Re: Use Git to manage dotfiles

git-home looks promissing. Contrary to most other git-based solutions it stores permissions too.

Offline

#5 2009-06-10 20:58:13

Yannick_LM
Member
Registered: 2008-12-22
Posts: 142

Re: Use Git to manage dotfiles

- Some put the files in ~/dotfiles/* and symlink them, often using a script. This sounds rather complicated to me.

This can in fact work quite well.

Currently, I got git repos in
.config/vim, .config/zsh and .config/awesome

with some symlinks:
.zshrc -> .config/zsh/zshrc
.vim ->.config/vim
.vimrc -> .config/vim/vimrc

and so on...

I got a branch for work and a branch for home for each repo, and everything is fine.

Offline

#6 2009-06-11 14:43:45

timetrap
Member
From: Here and There
Registered: 2008-06-05
Posts: 342
Website

Re: Use Git to manage dotfiles

Yannick_LM wrote:

- Some put the files in ~/dotfiles/* and symlink them, often using a script. This sounds rather complicated to me.

This can in fact work quite well.

Currently, I got git repos in
.config/vim, .config/zsh and .config/awesome

with some symlinks:
.zshrc -> .config/zsh/zshrc
.vim ->.config/vim
.vimrc -> .config/vim/vimrc

and so on...

I got a branch for work and a branch for home for each repo, and everything is fine.

I have the same style set up. It makes everything much easier.

.emacs -> ~/configs/emacs

And emacs git mode makes it easier as well ...

Offline

#7 2009-06-11 16:27:24

WhiteMagic
Member
Registered: 2007-03-01
Posts: 85

Re: Use Git to manage dotfiles

I tried both gibak and git-home-history but for me they were more trouble then help so I went with a simple git repository in my home directory.
At first I had a remote branch for each computer but after some merging this got messy. Now I have a single remote branch with a local branch on each computer for computer specific customizations. I commit changes to my config files on the master branch which gets pushed to a remote repository. The local branches are updated by rebasing them to the master branch. So far this worked ok for me.

I also have a rather extensive .gitignore file deciding which files are synched by git.

Offline

#8 2009-06-12 08:50:02

Mr.Elendig
#archlinux@freenode channel op
From: The intertubes
Registered: 2004-11-07
Posts: 4,092

Re: Use Git to manage dotfiles

I just run a git repo directly in ~, and just add the files I want to it, instead of doing git add .


Evil #archlinux@libera.chat channel op and general support dude.
. files on github, Screenshots, Random pics and the rest

Offline

#9 2009-06-14 17:27:44

Mogger
Member
From: Sweden
Registered: 2008-12-07
Posts: 153
Website

Re: Use Git to manage dotfiles

Thanks for all the input! I think I'll try to put all dotfiles in a separate directory and hardlink.

Those of you who do it this way, do you have a script (preferable bash) or do you run ln 'manually'?

Offline

#10 2009-06-14 17:58:14

cinan
Member
From: Slovakia
Registered: 2008-07-04
Posts: 251
Website

Re: Use Git to manage dotfiles

I just do 'git add .' 'git commit -a' and 'git push'. Manually smile

Offline

#11 2009-11-13 16:07:09

Urfaust
Member
From: Germany
Registered: 2009-01-30
Posts: 164

Re: Use Git to manage dotfiles

Hi

I'm playing around with git to manage my dotfiles. I set up a bare repo on my NAS and a local repository under ~/. I added the remote repo to the local one so I can push and pull. This works for files like .bashrc because it is stored under ~/. Now I want to hard link files like rc.conf and others stored under /etc. When I try to create a hardlink I get an error "invalid link across devices" because /home and / are on seperated partitions. So is it a good idea to softlink those files (ln -s)? Will this work, too?

Another question:
How could I restore all files if I lost them/set up a new machine? First thing would be to clone the repo from the server and then? I would have the ~/dotfiles/ repo will all files in it, do I have to manually cp the files in this directory to where they belong to (cp ~/dotfiles/rc.conf /etc/rc.conf and so on..)?
Thanks for answering my noob questions. wink

Offline

#12 2009-11-13 16:27:24

Mogger
Member
From: Sweden
Registered: 2008-12-07
Posts: 153
Website

Re: Use Git to manage dotfiles

Guess I should update this topic with the solution I arrived at:

I have a ~/.dotfiles directory now and create softlinks in ~ (e.g. ~/.bashrc -> ~/.dotfiles/bashrc, ~/.vim -> ~/.dotfiles/vim). To create the symlinks I use the following script:

#!/bin/bash

DIR=/home/hans/.dotfiles/

mkdir -p ~/dotfiles_old

cd $DIR
for i in *
do
    mv ~/.$i ~/dotfiles_old/
    ln -s $DIR/$i ~/.$i
done

rm ~/.make.sh

Not very beautiful but it works. wink (It's in ~/.dotfiles/, if you wonder what the last line is for).

The master branch contains common configuration for all computers. Each computer has a local branch to handle local customizations. When I want a change to apply globally, I checkout master or use cherry-pick, and finally rebase the local branch.

Offline

#13 2009-11-13 16:37:54

anrxc
Member
From: Croatia
Registered: 2008-03-22
Posts: 834
Website

Re: Use Git to manage dotfiles

I use this script to copy files that have changed into ~/dotfiles. For every file and directory in ~/dotfiles it checks if a .<name> exists in home, then compares and makes a copy. Main repo is on my workstation, every other machine has a branch with local changes. Workstation also has a public branch stripped of all sensitive data, so I can share my dotfiles with others.

Last edited by anrxc (2009-11-13 16:41:49)


You need to install an RTFM interface.

Offline

#14 2009-11-13 16:58:02

Urfaust
Member
From: Germany
Registered: 2009-01-30
Posts: 164

Re: Use Git to manage dotfiles

Ehm, now I am confused.:D
Why are those scripts necessary? If I create a softlink, lets say

ln -s /etc/rc.conf ~/dotfiles/rc.conf

why do I need to run the script? The name of the file will not change, so why is it necessary to create the link again?

Offline

#15 2009-11-13 17:40:08

Mogger
Member
From: Sweden
Registered: 2008-12-07
Posts: 153
Website

Re: Use Git to manage dotfiles

It's not - the script is for the first time I set it up. Just a little convenient thing. smile

Offline

#16 2009-11-13 17:44:34

Urfaust
Member
From: Germany
Registered: 2009-01-30
Posts: 164

Re: Use Git to manage dotfiles

Ah ok, thought you run this everytime you change something.:rolleyes:
Thanks for your answers, folks.;)

Offline

#17 2009-11-15 10:08:05

Urfaust
Member
From: Germany
Registered: 2009-01-30
Posts: 164

Re: Use Git to manage dotfiles

Mhh, problems. wink

I did the following in my ~/, ~/dotfiles is the folder where the git repo is placed:

echo 'testtesttest'> testfile
ln -s ~/testfile ~/dotfiles/testfile
cd dotfiles/
git status

worked like expected:

git status 
# On branch master
# Your branch is ahead of 'origin/master' by 6 commits.
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#    testfile
nothing added to commit but untracked files present (use "git add" to track)

then

git add .

git status 
# On branch master
# Your branch is ahead of 'origin/master' by 6 commits.
#
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#    new file:   testfile
#

git commit -m 'testfile'
[master 818fefe] testfile
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 120000 testfile

Ok, now for the problem.:D

cd ~/
nano testfile (modifying the testfile)
cd dotfiles/
git status
# On branch master
# Your branch is ahead of 'origin/master' by 7 commits.
#
nothing to commit (working directory clean)

yikes

I modified the testfile but git is not recognizing it?
I don't get it, also a 'git add .' did nothing. Why isn't git aware that I changed the testfile?

Thanks for help.

Offline

#18 2009-11-15 10:15:02

Mogger
Member
From: Sweden
Registered: 2008-12-07
Posts: 153
Website

Re: Use Git to manage dotfiles

I think you should do it the other way around - real files in ~/dotfiles (git repo) and symlinks in ~. For example, ~/.bashrc -> ~/dotfiles/bashrc.

Offline

#19 2009-11-15 10:22:43

Urfaust
Member
From: Germany
Registered: 2009-01-30
Posts: 164

Re: Use Git to manage dotfiles

Mhh, that's not really what I want. If I don't want to use the git repo anymore I delete ~/dotfiles and everything is gone. If I do it the other way round this is not possible..:/
Now I have a central folder with symlinks. Otherwise there would be a bunch of files in it and symlinks spread all over the filesystem.

Last edited by Urfaust (2009-11-15 10:25:36)

Offline

#20 2009-11-15 10:40:48

Mogger
Member
From: Sweden
Registered: 2008-12-07
Posts: 153
Website

Re: Use Git to manage dotfiles

Hm. In that case, have you tried hardlinks?

Offline

#21 2009-11-15 10:54:53

Urfaust
Member
From: Germany
Registered: 2009-01-30
Posts: 164

Re: Use Git to manage dotfiles

Mogger wrote:

Hm. In that case, have you tried hardlinks?

Yes, see Posting #11. But

Urfaust wrote:

This works for files like .bashrc because it is stored under ~/. Now I want to hard link files like rc.conf and others stored under /etc. When I try to create a hardlink I get an error "invalid link across devices" because /home and / are on seperated partitions. So is it a good idea to softlink those files (ln -s)? Will this work, too?

This seems to be a doom loop.;)

Offline

#22 2009-11-15 10:58:56

Mogger
Member
From: Sweden
Registered: 2008-12-07
Posts: 153
Website

Re: Use Git to manage dotfiles

Ah, sorry. I had read that, but forgot about it. Then I don't know any other solutions (other than doing the other way around).

Offline

#23 2009-11-15 11:06:08

Urfaust
Member
From: Germany
Registered: 2009-01-30
Posts: 164

Re: Use Git to manage dotfiles

Ok, but thanks for your answers.:)

Offline

#24 2010-06-24 15:20:00

tzervo
Member
From: Athens
Registered: 2009-04-03
Posts: 86

Re: Use Git to manage dotfiles

@OP: you can also change your $HOME variable to /home/yourname/dotfiles, so you can avoid symlinking. This was proposed here for other reasons but I found out it worked nice for dotfiles versioning as well

EDIT: sorry for necrobumping, I read the post's date wrong...

Last edited by tzervo (2010-06-24 17:57:25)

Offline

Board footer

Powered by FluxBB