cd ~
git init --bare $HOME/.dotfiles
alias conf='/usr/bin/git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME'
conf config status.showUntrackedFiles no
-
Browse the home directory.
-
Create the git bare repository too keep track of the files.
-
Create an alias to interact with your configuration repository.
-
Set - local to the repository - to hide files we are not explicitly tracking yet.
Is a good idea to add the alias to your shell configuration file. In my case under .aliases.
After the setup any file within the $HOME folder can be versioned with normal git commands, replacing git with the config alias.
conf status
conf add .vimrc
conf commit -m "Add vim configuration file"
conf push
- Recreate the alias.
- The source repository ignores the folder it'll cloned, so to avoid recursion gitignore the repository folder.
- Clone the repository into the chosen folder.
- Checkout the content from the repository to your
$HOME
.
alias conf='/usr/bin/git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME'
echo ".dotfiles" >> $HOME/.gitignore
git clone --bare https://github.com/maxrodrigo/homesick $HOME/.dotfiles
conf checkout
If the pulled files already exist git will return an error: Please move or remove them before you can switch branches.
Remove: conf checkout 2>&1 | egrep "\s+\." | awk {'print $1'} | xargs -I{} rm -rf {}
Or backup: conf checkout 2>&1 | egrep "\s+\." | awk {'print $1'} | \ xargs -I{} mv {} .conf-backup/{}
And re-run: conf checkout
As a las step set local to hide files we are not explicitly tracking:
conf config --local status.showUntrackedFiles no
Thanks to Nicola Paolucci and StreakyCobra.