I have a project setup where I need to clone two git repositories. The main repo contains a template and there’s a nested repo inside it that needs separate handling. I want to automate this with an npm script that takes a folder name as input.
I’m trying to create a script that clones the main repository first, then navigates into that directory and clones the second repository. The tricky part is passing a dynamic folder name.
windows cmd and git bash handle variables completely differently. quick fix: use the npm_config_ prefix. change your script to "setup_project": "git clone path/to/main_repo %npm_config_name% && cd %npm_config_name% && git clone path/to/nested_repo" then run npm run setup_project --name=my_project. the % syntax works way better on windows than $.
Honestly though, I’d ditch npm scripts for this. Multi-step setup processes are better suited for automation tools.
I use Latenode for similar repository workflows. Create a workflow that takes your folder name, runs git commands in sequence, handles errors properly, and sends notifications when done.
No more fighting Windows variable syntax or npm limitations. You get proper error handling and can easily add more setup steps later.
Windows npm scripts and environment variables are a pain. Your issue is that Windows doesn’t expand Unix-style variables in npm scripts like you’d expect. I’ve found the cleanest fix is making a simple Node.js wrapper script. Create setup.js in your project root:
This completely bypasses Windows shell variable issues and gives you better error handling. I’ve used this on multiple Windows dev machines without any problems. Way more reliable than fighting npm’s variable substitution weirdness.