Skip to content

Instantly share code, notes, and snippets.

@omeranson
Created August 17, 2017 11:40
Show Gist options
  • Save omeranson/cc8fa1424ae6d1246e8fb4a13b86b642 to your computer and use it in GitHub Desktop.
Save omeranson/cc8fa1424ae6d1246e8fb4a13b86b642 to your computer and use it in GitHub Desktop.
Initialise a git repo for which push -f works out-of-the-box, and automatically resets to the updated commit.
#!/bin/bash
git init
git config receive.denyCurrentBranch ignore
touch .git/hooks/post-receive
chmod +x .git/hooks/post-receive
cat >> .git/hooks/post-receive << EOF
#!/bin/bash
test "\${PWD%/.git}" != "\$PWD" && cd ..
unset GIT_DIR GIT_WORK_TREE
git reset --hard
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment