Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Efficient way to manage a git repository for local config files

Tags:

git

config

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 home dir.

I found this approach has some problems:

  • git gui takes forever, because it recursively scans the whole home dir.
  • I sometimes accidentally add files to the config repo that should go to a new repo (I create a new project, say in ~/projects/foo, forget it doesn't yet have a git repo initialized, and execute git add bar.xyz in the foo directory. This results in a file being added to the config repo).

I'm not sure it is wise to have git repositories nested under a directory that already has a git repository, although I haven't yet encounter any fundamental problems with this.

Is there a better approach, or is this a standard way in which people store local config files in git?

like image 887
Jan Wrobel Avatar asked Jun 13 '13 07:06

Jan Wrobel


People also ask

Should I add project configuration files to git?

The short answer to your question is Yes. I wouldn't hesitate to recommend Git (or any other version control software) to keep track of configuration files.

How do I manage a git repository?

Create and Manage a Git RepositoryClick on the Settings page for your account, then on the SSH and GPG Keys section. On that page, click the “New SSH key” button. After you have clicked on the New SSH key button a panel will appear in which you should then input a Title for the key and the private key itself.

How do I manage large git repository?

Using submodules One way out of the problem of large files is to use submodules, which enable you to manage one Git repository within another. You can create a submodule, which contains all your binary files, keeping the rest of the code separately in the parent repository, and update the submodule only when necessary.

Where should I put my local git repository?

As the git repository is contained inside your work directory, just place the work directories wherever is most convenient.


2 Answers

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.

like image 177
Jokester Avatar answered Oct 06 '22 20:10

Jokester


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).

like image 35
Richard Hansen Avatar answered Oct 06 '22 20:10

Richard Hansen