Koen
Koen

Reputation: 321

Why it use a git bare repo here?

I read an old thread from HackNews about What do you use to manage dotfiles? In this reply, I didn't get the reason he uses git bare repo. I think that git repo (git init) could do the same thing as he described.

Upvotes: 1

Views: 192

Answers (1)

Schwern
Schwern

Reputation: 164799

git init --bare $HOME/.myconf
alias config='/usr/bin/git --git-dir=$HOME/.myconf/ --work-tree=$HOME'
config config status.showUntrackedFiles no

you can use different branches for different computers, you can replicate you configuration easily on new installation.

While using your dotfiles on multiple computers you will want to be able to push and pull changes with the remote. The remote needs to be a bare repository.

The separate work tree is mostly unnecessary and just makes things more complicated. There's no harm in having .git/ in your home directory and it makes it obvious what's going on and how to use it. One can instead treat $HOME/.myconf like any other remote.

You then need to turn your home directory into a Git checkout. There's a sort of chicken/egg problem, you can't clone into your existing home directory, but you need to turn your existing home directory into a Git checkout.

Handle this by initializing and adding the remote manually.

# Create the bare, empty repository
git init --bare $HOME/.myconf

# clone to your home directory, but don't check it out; it's empty.
cd $HOME
git clone --no-checkout $HOME/.myconf

# ignore non-dotfiles and .myconf
echo '[a-zA-Z0-9]*' >> .gitignore
echo '.myconf' >> .gitignore

# add your existing dotfiles
git add .*

# commit
git commit -m 'From existing home directory on <machine>`

(Using $HOME/.myconf as the working tree skips this step, but it complicates everything going forward.)

Once that's done, your home directory is a clone of .myconf. Commit, push, and pull as normal.

Then, assuming you have ssh access, git clone user@host:~/.myconf on any other machine. You can push and pull as you would with any remote repository.

Upvotes: 1

Related Questions