Skip to content
Back to skills

5 Safe Branch Operations

ASecurity

Sub-skill of git-sync-manager: 5. Safe Branch Operations.

  • 17 stars
  • 0 votes
  • 0 copies
  • 4 views
  • Added September 9, 2026
documentationgobashgit

Security analysis

A100/100

Scanned September 9, 2026

npx -y skills add vamseeachanta/workspace-hub --skill 5-safe-branch-operations --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of 5 Safe Branch Operations?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for 5 Safe Branch Operations
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/vamseeachanta-5-safe-branch-operations/badge)](https://www.skillsdirectory.com/skills/vamseeachanta-5-safe-branch-operations)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: git-sync-manager-5-safe-branch-operations
description: 'Sub-skill of git-sync-manager: 5. Safe Branch Operations.'
version: 1.0.0
category: _core
type: reference
scripts_exempt: true
---

# 5. Safe Branch Operations

## 5. Safe Branch Operations


Switch branches safely across repositories:

```bash
#!/bin/bash
# ABOUTME: Safe branch switching across repositories
# ABOUTME: Validates branch existence and checks for uncommitted changes

switch_branch() {
    local repo="$1"
    local target_branch="$2"

    if [[ ! -d "$repo/.git" ]]; then
        echo "skip: not a git repo"
        return 1
    fi

    cd "$repo" || return 1

    # Check for uncommitted changes
    if ! git diff --quiet 2>/dev/null || ! git diff --cached --quiet 2>/dev/null; then
        echo "blocked: uncommitted changes"
        return 1
    fi

    # Check if branch exists locally
    if git show-ref --verify --quiet "refs/heads/$target_branch" 2>/dev/null; then
        git checkout "$target_branch" 2>/dev/null
        echo "switched: local branch"
        return 0
    fi

    # Check if branch exists remotely
    if git show-ref --verify --quiet "refs/remotes/origin/$target_branch" 2>/dev/null; then
        git checkout -b "$target_branch" "origin/$target_branch" 2>/dev/null
        echo "switched: created from remote"
        return 0
    fi

    echo "skip: branch not found"
    return 1
}

# Batch branch switch
batch_switch_branch() {
    local target_branch="$1"
    shift
    local repos=("$@")

    echo "Switching to branch: $target_branch"
    echo ""

    for repo in "${repos[@]}"; do
        echo -n "→ $repo: "
        switch_branch "$repo" "$target_branch"
    done
}
```

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.