Created
October 25, 2025 22:34
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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