Skip to content

Instantly share code, notes, and snippets.

@scott1991
Last active July 17, 2023 13:27
Show Gist options
  • Save scott1991/1c0c49a258e60102e3b9afcaf95e0358 to your computer and use it in GitHub Desktop.
Save scott1991/1c0c49a258e60102e3b9afcaf95e0358 to your computer and use it in GitHub Desktop.
A script to create a tar archive from a directory, excluding files as per the .gitignore file.
#!/bin/bash
if [ $# -eq 0 ]; then
echo "Please provide the target directory path as an argument."
exit 1
fi
CURRENT_DIR=$(pwd)
TARGET_DIR=$1
DIR_NAME=$(basename $TARGET_DIR)
# Change to the target directory
cd $TARGET_DIR
# Create the archive using tar command
tar -cvf ${CURRENT_DIR}/${DIR_NAME}.tar $(git ls-files)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment