how to sync HOME/bin directories with git

this is one way to keep changes to $HOME/bin in sync between hosts. this has been created from memory, so is not 100% guaranteed. :(

it assumes the following:

  • each host has a git repository living at $HOME/GITrepo.

  • each host has a bin directory in the home directory at $HOME/bin.

  • git access has been set up between hosts, e.g., passwordless ssh via keys.

  • for the sake of illustration, the hosts used are:

    • central server: grox

    • worksatation : idox

steps

grox

create repo:

# FIXME: must be an easier way,
# but don't have time to research it, right now...
git init $HOME/GITrepo/bin
mv $HOME/GITrepo/bin/.git/* $HOME/GITrepo/bin
rmdir $HOME/GITrepo/bin/.git

adjust configuration:

cat >$HOME/GITrepo/bin/config <<EOM
[core]
  repositoryformatversion = 0
  filemode = true
  bare = false
  worktree = /home/dave/bin
EOM

tell the bin dir where the repo lives:

echo 'gitdir: /home/dave/GITrepo/bin' >$HOME/bin/.git

add files:

cd $HOME/bin
git add *
git commit
git status

test:

cd $HOME/bin
touch tst
git add tst
git commit -m 'tst: added as a test.'
idox

create repo:

git clone ssh://grox.net/home/dave/bin/ $HOME/GITrepo/bin
cd $HOME/GITrepo/bin
mv .git/* .
rmdir .git

adjust configuration:

cat >$HOME/GITrepo/bin/config <<EOM
[core]
  repositoryformatversion = 0
  filemode = true
  bare = false
  logallrefupdates = true
  worktree = /home/dave/bin
[remote "origin"]
  url = ssh://grox.net/home/dave/bin/
  fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
  remote = origin
  merge = refs/heads/master
EOM

tell the bin dir where the repo lives:

  echo 'gitdir: /home/dave/GITrepo/bin' >$HOME/bin/.git

sync the files

# overkill, but i'm paranoid
cd $HOME/bin
git fetch
git pull
git status

should have empty tst file:

  ls -l $HOME/bin/tst

test push:

cd $HOME/bin
git rm tst
git commit -m 'tst: deleted. testing from idox.'
git status
git log
ssh grox "(cd bin; git checkout --detach; )"
git push
ssh grox "(cd bin; ls -l tst; git checkout master; git log; )"