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.