Efficient way to manage a git repository for local config files

后端 未结 2 1056
广开言路
广开言路 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:26

    I keep my dotfiles in a Git repository like you do—my home dir is a Git repository.

    • git gui: I rarely use it, so I'm not really sure how its performance is impacted by lots of untracked files. However, I do have a ~/.gitignore file that simply contains *. Perhaps ignoring everything will speed up git gui for you.

    • Accidentally adding files: Creating a ~/.gitignore file that simply contains * also solves the problem of accidentally adding a file to your dotfiles repository when you forget to initialize a new project repository (it'll tell you to use -f if you really want to add the file).

    • I've never had a problem with nested repositories.

    Some notes:

    • The main reason why I set my ~/.gitignore to * is so that git status doesn't show every file in my home directory. It forces me to use git add -f all the time, which is a bit annoying, but not that big of a deal.

    • Get in the habit of using git clean -dx instead of git clean -dxf. You'll have to remember to run git config clean.requireForce false in new project repositories, but it'll prevent you from accidentally deleting all of your files in your home directory if you're not in the directory you think you're in.

    • Git sometimes decides to reset file permissions. This can be bad if you want to keep sensitive files (chmod og-rwx) in your Git repository. I handle this via a post-checkout hook that fixes permissions of certain files and directories (e.g., ~/.ssh/authorized_keys).

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题