Instantly share code, notes, and snippets.

Embed
What would you like to do?
Git hook (post-receive): update working tree on PUSH
#!/bin/sh
#
# This hook is placed in Bare repository and it updates Working tree whenever a PUSH
# is executed
#
# Assuming following file structure:
# .
# |-- myproject
# |-- myproject.git
# set WORKTREE=../myproject
#
# Where myproject.git - current bare repo and myproject - working directory
# To enable this hook, rename this file to "post-receive" and make sure it is executable
#
WORKTREE=../myproject
GITDIR=$WORKTREE.git
cd $WORKTREE
# update the working tree
git --work-tree=./ --git-dir=$GITDIR checkout -f
git --work-tree=./ --git-dir=$GITDIR clean -fd
# return to git directory
cd $GITDIR
# we have to read stdin in order to avoid
# sideband demutiplexer error
# more details here: http://bit.ly/PzbRwo
while read oldrev newrev refname
do
:
done
@Djabx

This comment has been minimized.

Show comment
Hide comment
@Djabx

Djabx Mar 6, 2017

Thank you, exactly what I needed !

One question, why do you use checkout -f followed by clean -fd and not reset --hard ?

Djabx commented Mar 6, 2017

Thank you, exactly what I needed !

One question, why do you use checkout -f followed by clean -fd and not reset --hard ?

@ivanovaleksey

This comment has been minimized.

Show comment
Hide comment
@ivanovaleksey

ivanovaleksey Jul 22, 2017

Thank you @sergeylukin.
But the link you provided says that one should read everything from STDIN before running actual script.

ivanovaleksey commented Jul 22, 2017

Thank you @sergeylukin.
But the link you provided says that one should read everything from STDIN before running actual script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment