LoginSignup
2
2

More than 3 years have passed since last update.

dotfiles をgit bare repoで簡単に管理する

Last updated at Posted at 2019-07-13

Dotfilesどうやって管理していますか

2019/07/19 update

TL;DR

今までは\$HOME/dotfiles以下で管理して、symlinkを貼っていた。(一部スクリプト化)
一方で、symlinkが適切に貼られなかったときなど管理が煩雑だった。
git bare repoを使うことで、$HOME直下の一部のdotfileをtrackして、symlinkを貼らずにcloneだけで設定が終わるようになった。

設定方法 (bash使用を仮定)

mkdir $HOME/dotfiles
git init --bare $HOME/dotfiles  #ここには.bashrcなどを置かない
echo 'alias config='/usr/bin/git --git-dir=$HOME/dotfiles/ --work-tree=$HOME'' >> $HOME/.bashrc
config config --local status.showUntrackedFiles no

使用法

git add などの代わりに config add など使う。

config add .bashrc
config commit -m "Add .bashrc"
remoterepo='https://github.com/xxx/dotfiles'
config remote add origin $remoterepo
config push origin master

環境構築方法

新しく環境構築する側で

  • .bashrc か .zshrcに aliasを以下のように設定しておく。
alias config='/usr/bin/git --git-dir=$HOME/dotfiles/ --work-tree=$HOME'
  • dotfiles repoを引っ張ってくる
git clone --bare <git-repo-url> $HOME/dotfiles
source .bashrc
  • dotfiles を$HOMEで展開する
cd 
config checkout

もともとのdotfiles が存在する場合errorとなる場合があります。
そのときここを読んでみてください。

appendix

git bare repoについて

git initで作られる.git ディレクトリの内容(commit historyなど)が作られる。詳しくは参考資料参照。
あとはせっかくgitをつかっているので、hostによってbranch切りましょう。

参考資料


  • リンク切れ修正、環境再構築の方法を追記 (2019/07/19)
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2