Skip to content

Instantly share code, notes, and snippets.

@dayne
Created June 20, 2022 23:12
Show Gist options
  • Save dayne/35000808e1fdc185fcaf5b4dea12ab28 to your computer and use it in GitHub Desktop.
Save dayne/35000808e1fdc185fcaf5b4dea12ab28 to your computer and use it in GitHub Desktop.
$HOME as GIT

Managing your home's dot files as git repo an approach well documented by @durdn.

initial setup

git init --bare $HOME/.cfg
alias cfg='/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME'
cfg config --local status.showUntrackedFiles no
echo ".cfg" >> .gitignore
cfg add .gitignore
echo "alias cfg='/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME'" >> $HOME/.bashrc

using it

cfg status
cfg add .vimrc
cfg commit -m "Add vimrc"
cfg add .bashrc
cfg commit -m "Add bashrc"
cfg push

install on new system

Get the setup script local and run it: ~/.bin/cfgsetup

The key alias:

alias cfg='/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME'

git clone --bare [email protected]:dayne/dots.git $HOME/.cfg
alias cfg='/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME'
cfg config --local status.showUntrackedFiles no
cfg checkout
# fix/move any conflicting files .. mv CONFLICT CONFLICT_backup
# repeat the cfg checkout as needed

NOTE YET copy-n-pasta ready

git clone --bare https://bitbucket.org/durdn/cfg.git $HOME/.cfg
function cfg {
   /usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME $@
}
mkdir -p .config-backup
cfg checkout
if [ $? = 0 ]; then
  echo "Checked out config.";
  else
    echo "Backing up pre-existing dot files.";
    cfg checkout 2>&1 | egrep "\s+\." | awk {'print $1'} | xargs -I{} mv {} .config-backup/{}
fi;
cfg checkout
cfg config status.showUntrackedFiles no
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment