Skip to content

Latest commit

 

History

History
174 lines (121 loc) · 4.55 KB

File metadata and controls

174 lines (121 loc) · 4.55 KB

🧭 Git Branch Synchronization & Recovery Guide

This documentation explains how to keep your testing branch up to date with your main branch,
and how to restore the main branch to a previous working snapshot if anything goes wrong.


📌 Overview

You are maintaining two branches in your GitHub repository:

  • main → The active development branch (updated daily)
  • testing → A stable snapshot branch (used as a secure backup point)

🧩 Workflow Summary

flowchart TD
    A[Start: main & testing branches exist] --> B[Work daily on main branch]
    B --> C[Periodically update testing branch with main's latest code]
    C --> D[testing acts as backup snapshot]
    D --> E[If main breaks, restore it from testing]
    E --> F[main and testing are in sync again]
Loading

⚙️ 1. Update testing branch from main

✅ Safe Steps

# Fetch the latest updates from GitHub
git fetch origin

# Switch to testing branch
git checkout testing

# Merge latest main changes into testing
git merge origin/main

# Resolve any merge conflicts (if they appear), then:
git commit

# Push updated testing branch to GitHub
git push origin testing

⚠️ Alternative: Force overwrite testing to be exactly like main

If you don’t need testing’s previous commits:

git checkout testing
git reset --hard origin/main
git push origin testing --force

🧠 Use this only if you want testing = main exactly.


💾 2. Use testing as a recovery snapshot

If something goes wrong in main, you can restore it from testing.

🩹 Option 1 — Hard reset (overwrite main completely)

git checkout main
git fetch origin
git reset --hard origin/testing
git push origin main --force
  • Main becomes identical to testing.
  • ⚠️ This rewrites history, so warn teammates before force-pushing.

🛡️ Option 2 — Safe revert (no history rewrite)

git checkout main
git revert --no-commit origin/testing..HEAD
git commit -m "Revert main back to testing snapshot"
git push origin main
  • This creates a new commit undoing all changes since testing.
  • Safe for shared/team repos.

🧰 Option 3 — Merge overwrite (preserve history but overwrite content)

git checkout main
git merge -s ours origin/testing -m "Reset main to testing state"
git push origin main
  • Keeps commit history intact.
  • Commonly used in production environments.

🏷️ 3. Tag stable snapshots for easy rollback

Before merging or resetting branches, create a tag for a known good version:

git checkout testing
git tag stable-2025-10-13
git push origin stable-2025-10-13

To restore from a tagged snapshot later:

git checkout main
git reset --hard stable-2025-10-13
git push origin main --force

🧭 Visual Guide: Recovery Flow

graph LR
    A[Main branch breaks] --> B{Do you want full overwrite?}
    B -- Yes --> C[git reset --hard origin/testing]
    B -- No --> D[git revert --no-commit origin/testing..HEAD]
    C --> E[Push with --force]
    D --> F[Commit revert and push normally]
    E --> G[Main restored successfully]
    F --> G[Main restored successfully]
Loading

🧩 Summary Table

Purpose Command Safe for Team?
Merge main → testing git merge origin/main
Force testing = main git reset --hard origin/main ⚠️
Restore main from testing (overwrite) git reset --hard origin/testing ⚠️
Restore main safely (revert) git revert --no-commit origin/testing..HEAD
Tag stable snapshot git tag stable-YYYY-MM-DD

🪶 Author Notes

  • This guide is designed for developers using VS Code connected to GitHub.
  • You can perform all of these steps from the VS Code terminal or the Source Control panel.
  • Keep your testing branch as your last stable checkpoint to ensure a safety net.

📘 Last Updated: October 13, 2025 Repository Purpose: Safe Git workflow between main and testing


Would you like me to:

  • 📄 generate this as a downloadable README.md file, or
  • 💻 open it in a VS Code–ready markdown canvas so you can edit it interactively?