hyperspectral-orchard / add_and_push_files.sh
Eli-S's picture
Added file ./add_and_push_files.sh
27c67cd unverified
raw
history blame
1.35 kB
#!/bin/bash
# Set the directory to search for files (current directory by default)
TARGET_DIR=${1:-.}
# Set the size threshold for using Git LFS (in bytes, e.g., 10MB)
LFS_THRESHOLD=$((10 * 1024 * 1024)) # 10MB
# Check if the directory exists
if [ ! -d "$TARGET_DIR" ]; then
echo "Directory $TARGET_DIR does not exist."
exit 1
fi
# Navigate to the target directory
cd "$TARGET_DIR" || exit
# Ensure Git LFS is initialized
git lfs install --skip-smudge
# Find all files recursively
find . -type f | while read -r file; do
# Get the file size in bytes
FILE_SIZE=$(stat --format=%s "$file")
if [ "$FILE_SIZE" -ge "$LFS_THRESHOLD" ]; then
# Track the file with Git LFS
git lfs track "$file"
echo "Tracked large file with LFS: $file"
fi
# Add the file to the Git staging area
git add "$file"
# Commit the file with a message, ignoring empty commits
git commit -m "Added file $file" || {
echo "Skipped empty commit for $file"
continue
}
# Push the commit to the remote repository
git push
echo "Processed $file"
done
# Commit and push the updated .gitattributes file (if any)
if git diff --cached --name-only | grep -q '.gitattributes'; then
git commit -m "Updated .gitattributes for LFS" || echo "No changes to .gitattributes"
git push
fi