Efficient way to manage a git repository for local config files

后端 未结 2 1063
广开言路
广开言路 2021-02-15 15:42

I store my config files (~/.bashrc, ~/.emacs, ~/emacs, etc.) in git. The way I configured this was simply to add a git repository in the h

2条回答
  •  自闭症患者
    2021-02-15 16:28

    I am using a git repo to manage the dotfiles. It contains:

    1. a directory dotfiles, which contains the actual dotfiles/dotdirs I want to track.
    2. a shell script, to create symbolic link of dotfiles/.* in $HOME, like

      for dotfile in dotfiles/.* ; do
        case $(basename $dotfile) in
          .)
            ;;
          ..)
            ;;
          *)
            ln -sv $(realpath dotfile) $HOME/$(basename $dotfile)
            ;;
        esac
      done
      

    The script is manually runned after I add something new in dotfiles(normally by moving a dotfile into repo), or in a new and clean $HOME.

    The repo can reside anywhere. I have a clone in $HOME on each host I am using.

    In this way I have a much smaller and non-nested work tree, to track the dotfiles selectively.

    p.s. You may want to add entries like dotfiles/.config/* to .gitignore, it contains many files I don't want to track.

提交回复
热议问题