Skip to content

Instantly share code, notes, and snippets.

@narskidan
Created August 28, 2024 19:15
Show Gist options
  • Save narskidan/de63964688fbca5bd1b4c28fb6801a35 to your computer and use it in GitHub Desktop.
Save narskidan/de63964688fbca5bd1b4c28fb6801a35 to your computer and use it in GitHub Desktop.
Backup my git repos before switching to new laptop
#!/bin/bash
cd ~/Documents/Code
for directory in *; do
if ! [ -d "$directory" ]; then continue; fi
cd "$directory"
# Check if this directory is a Git repository
if git rev-parse --is-inside-work-tree; then
git pull
git add .
git commit -m 'Backing up repos (switching to new laptop)'
git push --force
fi
## Change back to `~/Documents/Code`` directory
cd ..
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment