Skip to content

Instantly share code, notes, and snippets.

@DanielCardonaRojas
Created October 25, 2025 22:34
Show Gist options
  • Save DanielCardonaRojas/b6bd7b08d19462c843b8f48a56a5dc7f to your computer and use it in GitHub Desktop.
Save DanielCardonaRojas/b6bd7b08d19462c843b8f48a56a5dc7f to your computer and use it in GitHub Desktop.
git hook that will copy files or directories to a newly create worktrees. Designed for bare repos.
#!/bin/bash
if [[ "$1" == "0000000000000000000000000000000000000000" ]]; then
paths=(.mcp.json .claude CLAUDE.md AGENTS.md)
basepath=$(dirname $(pwd))
worktree=$(basename $(pwd))
for path in "${paths[@]}"; do
# The file or directory to copy
target="$basepath/$path"
# The path of newly create worktree
destination="$(pwd)/$path"
if [[ -d "$target" ]]; then
cp -r "$target" "$destination"
echo "Copied directory: $path to $worktree"
elif [[ -f "$target" ]]; then
# It's a file
cp "$target" "$destination"
echo "Copied file: $path to $worktree"
else
echo "Warning: '$path' not found, skipping."
fi
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment