github-sync.sh is a simple yet powerful Bash script designed to streamline the synchronization of Git repositories located under the ~/scripts
directory. This script automates the process of fetching, stashing, pulling, and pushing changes to GitHub, ensuring that your local and remote repositories remain up to date with minimal effort.
- 📂 Automatic Repository Discovery: Scans the specified directory for Git repositories.
- ⏳ Interactive Selection with Timeout: Prompts the user to select a repository within 14 seconds, defaulting to
~/scripts
. - 🔄 Automated Syncing: Fetches the latest changes, handles stashing of local modifications, and rebases changes from GitHub.
- 🛠 Conflict Handling: Detects merge conflicts and prompts the user to resolve them manually.
- 📌 Auto-Commit & Push: Stages and commits any new changes before pushing them to the remote repository.
- 🔒 Error Handling: Provides meaningful feedback in case of invalid selections or Git errors.
Ensure you have the following installed on your system:
- 🐧 Linux/macOS (Compatible Bash environment)
- 🔧 Git (Ensure you have SSH authentication set up for GitHub)
- Clone the Repository:
git clone [email protected]:michaelbolanos/github-sync.git
- Make the Script Executable:
chmod +x github-sync.sh
- Move to a Global Location (Optional):
Now you can run it from anywhere using:
sudo mv github-sync.sh /usr/local/bin/github-sync
github-sync
Run the script with:
./github-sync.sh
or if installed globally:
github-sync
- Select a directory (defaults to
~/scripts
if no input is provided within 14 seconds). - Choose a repository from the detected list.
- Sync process starts:
- Fetches the latest changes from the remote repository.
- Detects and stashes any local modifications.
- Rebases with the latest remote changes.
- Re-applies stashed changes (if applicable).
- Stages, commits, and pushes any new local changes.
- Completion message confirming a successful sync or warning of conflicts if they arise.
If a merge conflict occurs, the script will notify you:
⚠️ Merge conflict detected! Manually resolve and re-run the script.
Resolve conflicts manually using:
git status
git mergetool
git rebase --continue
Once resolved, re-run the script to complete the sync process.
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Feel free to fork the repo and submit pull requests.
🚀 Keep your repositories in sync effortlessly!