-
Notifications
You must be signed in to change notification settings - Fork 0
How to store configs in a git repository
Storing configs in a git repo allows you to keep them all in the same place, backed up online, easily synchronizable, and maybe with some extra added features. To set it up you should first create a bare git repo.
git init --bare $HOME/dotfilesCreate a bare repository
Think of GitHub. git already stores all the information about the files and their history in the .git folder. Why does GH need to store a copy of this information on the server then? Sure you, using the UI, see the files, but they can be generated quite easily and don't require GH to store them on the server. This is precisely what the bare repo is: a directory with an arbitrary name that only contains the content of .git. The working tree can be anywhere and even in multiple places at once!
- It is your
$HOMEso you store other git repos in there and git doesn't like that. - You won't have any loose
.gitfolders in your$HOME.
Quite handy IMO.
Now that we have a bare repo and it doesn't really know where the files are we need to set up a shortcut to interfacing with it.
alias config='/bin/git --git-dir=$HOME/dotfiles/ --work-tree=$HOME'Alias a long git command for a shorter config
Put this into $HOME/.profile and add source .profile to your preferred .shellrc (.zshrc or .bashrc, etc). BTW you won't be able to use this alias unless you run the same command in the shell, restart your shell or run source .profile.
You can call this alias anything, but now that we have it we can use this alias the same way as a git command. Let's actually do that since we have some more setup to do.
config config --local status.showUntrackedFiles noPrevents git shatus from considering all the files in your $HOME
At this point, we are done! Following is a simple conclusion of what we have just done.
# Create a bare git repo in $HOME
git init --bare $HOME/dotfiles
# Create a shortcut for calling git
alias config='/bin/git --git-dir=$HOME/dotfiles/ --work-tree=$HOME'
# Show less files in git status
config config --local status.showUntrackedFiles no