Skip to content

Instantly share code, notes, and snippets.

@miraclx
Last active January 22, 2021 03:15
Show Gist options
  • Select an option

  • Save miraclx/00f063ea3b499d55f57cef3873bf6040 to your computer and use it in GitHub Desktop.

Select an option

Save miraclx/00f063ea3b499d55f57cef3873bf6040 to your computer and use it in GitHub Desktop.
Git hook for automating push to keybase git repos using a shared bare repo

How to

Don't forget to replace angle brackets <...> with actual values

  • Create a bare git repo (this would be the local shared remote)
git init --bare <repo-name>
cd <repo-name>
  • Add your keybase git repos as remotes of your bare repo
git remote add keybase-prv keybase://private/<username>/<repo-name>
git remote add keybase-pub keybase://public/<username>/<repo-name>
  • Add the git hook to auto update your remotes on push to the bare repo
mkdir -p hooks
curl -L https://gist.github.com/miraclx/00f063ea3b499d55f57cef3873bf6040/raw/post-update -o hooks/post-update
chmod +x hooks/post-update
  • Add your bare repo as a remote to your project
cd <project-dir>
git remote add keybase <absolute-path-to-bare-repo>
  • Push to your bare repo (this should, in turn, forward that push to keybase)
git push keybase --all
# or be specific with branches
git push keybase master develop
#!/bin/sh
d0() {
stdbuf -oL uniq -c \
| sed -uE 's/^\s*1 (.+)/| \1/;s/^\s*([0-9]+) (.+)/| \x1b[36m\1\x1b[0m \2/;'
}
echo "• Pushing to Keybase Private Git Repo"
git push keybase-prv $@ 2>&1 | d0
echo "• Pushing to Keybase Public Git Repo"
git push keybase-pub $@ 2>&1 | d0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment