Skip to content

Instantly share code, notes, and snippets.

@OllieJT
Created September 2, 2023 11:31
Show Gist options
  • Save OllieJT/39bb6d1253bda03b0f3f93f623b3d3b5 to your computer and use it in GitHub Desktop.
Save OllieJT/39bb6d1253bda03b0f3f93f623b3d3b5 to your computer and use it in GitHub Desktop.
cpgit - Copies a node project to a new directory while excluding node_modules and git history
#!/bin/bash
# Copies a node project to a new directory while excluding node_modules and git history
# Check for both source and destination directory arguments
if [ "$#" -ne 2 ]; then
echo "Required arguements: source_directory new_directory"
exit 1
fi
# Define source and new directory names
SOURCE_DIR="$1"
NEW_DIR="$2"
# Perform recursive copy while excluding certain folders
rsync -av --exclude '/node_modules' --exclude '/.git' "$SOURCE_DIR/" "$NEW_DIR/"
@OllieJT
Copy link
Author

OllieJT commented Sep 2, 2023

Recommended Setup

Assuming you save this to ~/scripts/cpgit.sh

Make the file executable

chmod +x ~/scripts/cpgit.sh

Alias the script in your ~/.bashrc or ~/.zshrc file

alias cpgit="~/scripts/cpgit.sh"

Example usage

cpgit ./source-folder ./destination-folder

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