Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions .github/workflows/cleanup-old-branches.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
---
name: Cleanup Old Branches

on:
workflow_dispatch:

jobs:
cleanup-branches:
runs-on: ubuntu-latest
permissions:
contents: write

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Delete old branches
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "=============================================================="
echo "Branch Cleanup Workflow"
echo "=============================================================="
echo ""
echo "Branches to be deleted:"

# List of branches to delete
branches=(
"container"
"copilot/add-ai-chatbot-agent"
"copilot/add-copilot-seats-view"
"copilot/add-github-copilot-integration"
"copilot/add-github-export-tool"
"copilot/add-team-usage-report-page"
"copilot/fix-29985769-1145060471-3d22a403-533a-4231-ba2c-189bc9958005"
"copilot/implement-ndjson-ingestion-pipeline"
"dependabot/npm_and_yarn/api/npm_and_yarn-aa68fbd092"
"feature-4"
"feature-chatbot-agent"
"feature-code-quality-security"
"feature-enhancements"
"feature-visual-refinements"
"main-1"
"test-chat-agent-interactions"
"testing-file-fetch"
)

# Display and count
for branch in "${branches[@]}"; do
echo " - $branch"
done
echo ""
echo "Total: ${#branches[@]} branches"
echo ""

# Delete each branch
deleted=0
failed=0

for branch in "${branches[@]}"; do
echo -n "Deleting '$branch'... "

# Check if branch exists
if git ls-remote --heads origin "$branch" | \
grep -q "refs/heads/$branch$"; then
if git push origin --delete "$branch" 2>&1; then
echo "✓ Deleted"
((deleted++))
else
echo "✗ Failed"
((failed++))
fi
else
echo "⊘ Not found (may already be deleted)"
((failed++))
fi
done

echo ""
echo "=============================================================="
echo "Summary:"
echo " Successfully deleted: $deleted"
echo " Failed/Not found: $failed"
echo "=============================================================="
echo ""
echo "Remaining branches:"
git ls-remote --heads origin | \
awk '{print $2}' | sed 's|refs/heads/||' | sort
85 changes: 85 additions & 0 deletions docs/BRANCH_CLEANUP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Branch Cleanup Documentation

## Overview
This document describes the process for cleaning up old branches in the GitHub-Copilot-Usage-Insights repository.

## Branches Identified for Removal
The following branches have been identified as old/obsolete and should be removed, keeping only the `main` branch:

1. `container`
2. `copilot/add-ai-chatbot-agent`
3. `copilot/add-copilot-seats-view`
4. `copilot/add-github-copilot-integration`
5. `copilot/add-github-export-tool`
6. `copilot/add-team-usage-report-page`
7. `copilot/fix-29985769-1145060471-3d22a403-533a-4231-ba2c-189bc9958005`
8. `copilot/implement-ndjson-ingestion-pipeline`
9. `dependabot/npm_and_yarn/api/npm_and_yarn-aa68fbd092`
10. `feature-4`
11. `feature-chatbot-agent`
12. `feature-code-quality-security`
13. `feature-enhancements`
14. `feature-visual-refinements`
15. `main-1`
16. `test-chat-agent-interactions`
17. `testing-file-fetch`

**Total: 17 branches to be removed**

## Methods for Branch Deletion

### Method 1: Using GitHub Actions Workflow (Recommended)
A GitHub Actions workflow has been created at `.github/workflows/cleanup-old-branches.yml`.

**Steps:**
1. Go to the repository on GitHub
2. Click on the "Actions" tab
3. Select "Cleanup Old Branches" workflow from the left sidebar
4. Click "Run workflow" button
5. Confirm and run

The workflow will automatically delete all the specified branches.

### Method 2: Using the Bash Script
A bash script has been provided at `scripts/delete-old-branches.sh`.

**Steps:**
```bash
# From the repository root
./scripts/delete-old-branches.sh
```

**Note:** This method requires proper Git authentication and push permissions.

### Method 3: Manual Deletion via Git Command Line
If you prefer to delete branches manually:

```bash
# Delete a single branch
git push origin --delete branch-name

# Or delete multiple branches at once
git push origin --delete branch1 branch2 branch3
```

### Method 4: Manual Deletion via GitHub UI
1. Go to the repository on GitHub
2. Click on "branches" (showing the branch count)
3. For each branch to delete:
- Find the branch in the list
- Click the trash icon on the right side
- Confirm deletion

## Verification
After deletion, verify that only the `main` branch remains (plus any active working branches):

```bash
git ls-remote --heads origin
```

Expected output should show only `main` and any active development branches.

## Notes
- The `main` branch is protected and will not be deleted
- Any currently active working branches (like PR branches) are excluded from deletion
- Deleted branches can be restored from the GitHub UI within a short time window if needed
81 changes: 81 additions & 0 deletions scripts/delete-old-branches.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/bin/bash
# Script to delete old branches from the repository
# This script will delete all branches except 'main' and the current working branch

set -e

echo "================================================================"
echo "Branch Cleanup Script for GitHub-Copilot-Usage-Insights"
echo "================================================================"
echo ""
echo "This script will delete the following branches from the remote repository:"
echo ""

# List of branches to delete
branches_to_delete=(
"container"
"copilot/add-ai-chatbot-agent"
"copilot/add-copilot-seats-view"
"copilot/add-github-copilot-integration"
"copilot/add-github-export-tool"
"copilot/add-team-usage-report-page"
"copilot/fix-29985769-1145060471-3d22a403-533a-4231-ba2c-189bc9958005"
"copilot/implement-ndjson-ingestion-pipeline"
"dependabot/npm_and_yarn/api/npm_and_yarn-aa68fbd092"
"feature-4"
"feature-chatbot-agent"
"feature-code-quality-security"
"feature-enhancements"
"feature-visual-refinements"
"main-1"
"test-chat-agent-interactions"
"testing-file-fetch"
)

# Display branches to be deleted
for branch in "${branches_to_delete[@]}"; do
echo " - $branch"
done

echo ""
echo "Total branches to delete: ${#branches_to_delete[@]}"
echo ""

# Ask for confirmation
read -p "Are you sure you want to delete these branches? (yes/no): " confirm

if [ "$confirm" != "yes" ]; then
echo "Operation cancelled."
exit 0
fi

echo ""
echo "Deleting branches..."
echo ""

# Counter for successful deletions
deleted_count=0
failed_count=0

# Delete each branch
for branch in "${branches_to_delete[@]}"; do
echo -n "Deleting branch '$branch'... "
if git push origin --delete "$branch" 2>/dev/null; then
echo "✓ Success"
((deleted_count++))
else
echo "✗ Failed (may already be deleted or doesn't exist)"
((failed_count++))
fi
done

echo ""
echo "================================================================"
echo "Cleanup Summary:"
echo " Successfully deleted: $deleted_count branches"
echo " Failed/Not found: $failed_count branches"
echo "================================================================"
echo ""
echo "Remaining branches (fetching current state from remote):"
git ls-remote --heads origin | awk '{print $2}' | sed 's|refs/heads/||' | sort
echo ""