gitupdate - Update Git Repositories

Overview

The gitupdate command pulls the latest changes in multiple git repositories within a directory tree. Instead of manually updating each repository, this command automatically finds and updates all of them in one operation. This is particularly useful when working with microservices, related projects, or monorepos.

Syntax

nmbl gitupdate <RootPath>

Arguments

Output

Shows update status for each repository, including any errors or conflicts encountered.

Examples

Update All Repositories in a Directory

nmbl gitupdate ~/projects

Finds and updates all git repositories under the projects directory.

Update Current Directory Tree

nmbl gitupdate .

Updates all repositories in the current directory and subdirectories.

Morning Update Routine

# Start your day by updating everything
nmbl gitupdate ~/workspace

Ensure all repositories are up to date before starting work.

Use Cases

Team Workspace Synchronization

nmbl gitupdate ~/company-projects

Keep all team repositories synchronized with their remotes.

Monorepo Management

nmbl gitupdate ~/monorepo

Update all sub-repositories within a monorepo structure.

Microservices Development

# Update all microservices at once
nmbl gitupdate ~/services

# Then check their status
nmbl gitstatus ~/services

Keep all related microservices in sync.

CI/CD Preparation

# In a build script
nmbl gitupdate /workspace/dependencies

# Then build
dotnet build

Update dependencies before building.

Weekly Sync

# Monday morning routine
nmbl gitupdate ~/projects

# Check for any issues
nmbl gitstatus ~/projects

Start the week with all repositories up to date.

How It Works

For each git repository found, the command:

  1. Checks if it’s a valid git repository
  2. Fetches latest changes from remote
  3. Attempts to pull (fast-forward merge)
  4. Reports success or any issues

Handling Conflicts

If a repository has:

Tips

Check Status Before Update

# See what will be affected
nmbl gitstatus ~/projects

# Then update
nmbl gitupdate ~/projects

# Verify everything updated
nmbl gitstatus ~/projects

Update Specific Branch

The command updates the currently checked out branch in each repository. To update a specific branch across all repos, you’d need to:

# For each repo, checkout the branch first
for repo in ~/projects/*/; do
  cd "$repo"
  git checkout main
done

# Then update all
nmbl gitupdate ~/projects

Automation

# Add to cron for automatic updates
0 9 * * 1 nmbl gitupdate ~/projects >> ~/git-update.log 2>&1

Schedule automatic updates every Monday at 9 AM.

Create a Helper Script

#!/bin/bash
# save as ~/bin/sync-all

echo "Checking status..."
nmbl gitstatus ~/projects

echo "Updating repositories..."
nmbl gitupdate ~/projects

echo "Final status..."
nmbl gitstatus ~/projects

Handle Multiple Workspaces

# Update personal projects
nmbl gitupdate ~/personal

# Update work projects
nmbl gitupdate ~/work

# Update open source contributions
nmbl gitupdate ~/opensource

Troubleshooting

Repository Skipped

If a repository is skipped, it might:

Pull Failed

Common reasons:

To fix, manually navigate to the repository and resolve the issue:

cd path/to/problematic/repo
git status
git pull
# Resolve any conflicts

Best Practices

Commit Before Update

# Ensure all changes are committed
nmbl gitstatus ~/projects | grep -i "modified"

# If any modified repos, commit them first

# Then update
nmbl gitupdate ~/projects

Backup Important Work

# Before a bulk update
git stash --include-untracked

# Update
nmbl gitupdate ~/projects

# Restore if needed
git stash pop

Review Changes After Update

# Update all repos
nmbl gitupdate ~/projects

# Review what changed in each
for repo in ~/projects/*/; do
  cd "$repo"
  git log --oneline -5
done