Skip to content

michaelbolanos/github-sync

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GitHub Sync Script

Overview

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.


Features

  • 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.

Prerequisites

  • ✅ Linux/macOS terminal with Bash
  • git, curl, and ssh installed
  • ✅ GitHub account

First-Time Setup (SSH + Token)

🔑 1. Generate an SSH Key

⚙️ Default (RSA):

The script auto-generates this if no key is found:

ssh-keygen -t rsa -b 4096 -C "you@example.com"

🔐 Modern Option (ECDSA):

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.


🔗 2. Add SSH Key to GitHub

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.


🔐 3. Create GitHub Personal Access Token (for API)

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).


Installation

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

Usage

./github-sync.sh

Or globally:

github-sync

Menu Options

  1. Sync All – Sync all repos in ~/scripts
  2. Sync Selected Repos – Pick specific ones to sync
  3. Sync One Repo – Enter a path manually
  4. Clone Repos Manually – Paste SSH URLs one by one
  5. Clone from GitHub Account – Enter GitHub username and token to clone and sync all repos
  6. View Log – Show sync logs
  7. Exit – Exit script

Merge Conflict Handling

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.


License

MIT License – see LICENSE.


Contributions

Fork the repo, suggest changes, and submit PRs.


Releases

No releases published

Packages

No packages published

Languages