Skip to content

Instantly share code, notes, and snippets.

@tajidyakub
Created May 25, 2018 12:24
Show Gist options
  • Save tajidyakub/78dc30e0d647c2c42581124cb0aca07c to your computer and use it in GitHub Desktop.
Save tajidyakub/78dc30e0d647c2c42581124cb0aca07c to your computer and use it in GitHub Desktop.
Creates a non bare remote repository which aware of submodules.

Remote GIT Repository with Submodules

Post-receive Hooks template

Create a template of post-receive hooks to be populated in the .git folder everytine we initialize a repo. The template directory should be registered in to the glogal git configuration. Create the hook subdirectory inside the folder.

$ git config --global init.templatedir '~/.git-templates'
$ mkdir -p ~/.git-templates/hooks

Create the file post-receive.sample inside the hook directory, and set the file to be executable chmod +x ~/.git-templates/hooks/post-receive.sample below is the content of the file.

#!/bin/sh
#
# An example hook script to update the working tree, including its
# submodules, after receiving a push.
#
# This hook requires core.worktree to be explicitly set, and
# receive.denyCurrentBranch to be set to false.
#
# To enable this hook, rename this file to "post-receive".

# Read standard input or hook will fail
while read oldrev newrev refname
do
:
done

# Unset GIT_DIR or the universe will implode
unset GIT_DIR

# Change directory to the working tree; exit on failure
cd `git config --get core.worktree` || exit

# Force checkout
git checkout --force

# Force update submodules
git submodule update --init --recursive --force

Init the repo

$ cd /path/to/your/working/folder
$ git init
$ git config --bool receive.denyCurrentBranch false
$ git config --path core.worktree ../
$ mv .git/hooks/post-receive.sample .git/hooks/post-receive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment