DEV Community

Cover image for πŸš€ Automate Your GitHub Backups with Bash (Stop Losing Code!)
Richard Chamberlain
Richard Chamberlain

Posted on • Edited on

πŸš€ Automate Your GitHub Backups with Bash (Stop Losing Code!)

Let’s be honestβ€”most of us have code scattered across laptops, old VMs, and forgotten directories. I was guilty of this too… until I automated my GitHub backup workflow using simple Bash scripts.

Here’s the high-level strategy:

  • πŸ“ Auto-Link New Projects to GitHub Repos
  • πŸ” Secure Authentication with SSH Keys & API Tokens
  • πŸ”„ Auto-Sync Code with Git and Rsync
  • ⏰ Fully Automate Backups via Cron Jobs

πŸ“„ Quick Example: Automating Code Sync

rsync -av --exclude='build/' --exclude='log/' "$SRC_DIR" "$DEST_GITHUB/"
git add .
git commit -m "Automated backup on $(date)"
git push origin main
Enter fullscreen mode Exit fullscreen mode

⏰ Automate with Cron (Daily at Midnight)

0 0 * * * /home/username/scripts/github_backup.sh
Enter fullscreen mode Exit fullscreen mode

With this setup, I no longer worry about losing codeβ€”or forgetting to commit it!


✨ Want the full, step-by-step guide with working scripts?
πŸ‘‰ Read the full post on my site!


πŸ’‘ How are you automating your workflow? Share your tips below!

For more content like this, tools, and walkthroughs, visit my site at Sebos Technology.

Top comments (0)