github-sync.sh
is a powerful and interactive Bash script that automates syncing and managing Git repositories under your ~/scripts
directory. It helps you stay in sync with GitHub through SSH authentication, GitHub API integration, and an interactive menu.
- ✅ SSH Key Setup – Generates an SSH key if missing and prompts you to add it to GitHub.
- 🔁 Auto-Sync Repos – Automatically fetches, stashes, pulls, commits, and pushes repos.
- 🌐 GitHub API Integration – Uses your GitHub token to fetch and clone all your repos.
- 📦 Auto Backup – Archives each repo before syncing.
- 🎨 Color UI + Alerts – Color-coded output with terminal sound notifications.
- 🔍 Interactive Menu – Sync all, selected, or one repo; clone manually or via API.
- 📜 Logging – All actions logged to
~/scripts/github-sync.log
.
- ✅ Linux/macOS terminal with Bash
- ✅
git
,curl
, andssh
installed - ✅ GitHub account
The script auto-generates this if no key is found:
ssh-keygen -t rsa -b 4096 -C "you@example.com"
For a smaller, faster, modern key:
ssh-keygen -t ecdsa -b 521 -C "you@example.com" -f ~/.ssh/id_ecdsa
Then add it to your ssh-agent:
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ecdsa
Update your GitHub SSH key accordingly.
Copy your public key:
cat ~/.ssh/id_rsa.pub # or id_ecdsa.pub if using ECDSA
Then go to: https://github.com/settings/keys
Click New SSH key, paste it in, and save.
Go to: https://github.com/settings/tokens
Click Generate new token (classic)
✅ Select scopes:
repo
read:user
Copy the token (you’ll need it for the script's "Clone from GitHub Account" option).
git clone git@github.com:michaelbolanos/github-sync.git
cd github-sync
chmod +x github-sync.sh
Optional (run globally):
sudo mv github-sync.sh /usr/local/bin/github-sync
./github-sync.sh
Or globally:
github-sync
- Sync All – Sync all repos in
~/scripts
- Sync Selected Repos – Pick specific ones to sync
- Sync One Repo – Enter a path manually
- Clone Repos Manually – Paste SSH URLs one by one
- Clone from GitHub Account – Enter GitHub username and token to clone and sync all repos
- View Log – Show sync logs
- Exit – Exit script
If you see:
⚠️ Merge conflict detected! Resolve manually and re-run the script.
Run:
git status
git mergetool
git rebase --continue
Then re-run the script.
MIT License – see LICENSE
.
Fork the repo, suggest changes, and submit PRs.