|
| 1 | +# Branch Protection Rules - MostroP2P |
| 2 | + |
| 3 | +## 🛡️ Protected Repositories |
| 4 | + |
| 5 | +The following `main` branches are now protected: |
| 6 | + |
| 7 | +- ✅ **mostro** (main daemon) |
| 8 | +- ✅ **mostro-core** (core library) |
| 9 | +- ✅ **app** (Flutter mobile client) |
| 10 | +- ✅ **mobile** (alternative mobile client) |
| 11 | +- ✅ **mostro-cli** (CLI tool) |
| 12 | +- ✅ **protocol** (protocol documentation) |
| 13 | + |
| 14 | +--- |
| 15 | + |
| 16 | +## 🚫 Active Restrictions |
| 17 | + |
| 18 | +### You CANNOT: |
| 19 | + |
| 20 | +1. **❌ Push directly to `main`** |
| 21 | + ```bash |
| 22 | + git push origin main |
| 23 | + # Error: Push to protected branch rejected |
| 24 | + ``` |
| 25 | + |
| 26 | +2. **❌ Force push** |
| 27 | + ```bash |
| 28 | + git push --force origin main |
| 29 | + # Error: Force push disabled |
| 30 | + ``` |
| 31 | + |
| 32 | +3. **❌ Delete the `main` branch** |
| 33 | + ```bash |
| 34 | + git push origin --delete main |
| 35 | + # Error: Branch deletion disabled |
| 36 | + ``` |
| 37 | + |
| 38 | +--- |
| 39 | + |
| 40 | +## ✅ Correct Workflow |
| 41 | + |
| 42 | +### 1. Create a feature branch |
| 43 | + |
| 44 | +```bash |
| 45 | +git checkout -b feature/my-feature |
| 46 | +# Make changes |
| 47 | +git add . |
| 48 | +git commit -m "feat: description of change" |
| 49 | +git push origin feature/my-feature |
| 50 | +``` |
| 51 | + |
| 52 | +### 2. Create Pull Request |
| 53 | + |
| 54 | +```bash |
| 55 | +# On GitHub: |
| 56 | +# 1. Go to https://github.com/MostroP2P/<repo>/pulls |
| 57 | +# 2. Click "New Pull Request" |
| 58 | +# 3. Select: base: main <- compare: feature/my-feature |
| 59 | +# 4. Add clear description |
| 60 | +# 5. Click "Create Pull Request" |
| 61 | +``` |
| 62 | + |
| 63 | +### 3. Code Review |
| 64 | + |
| 65 | +- ✅ **Minimum 1 approval required** before merge |
| 66 | +- ✅ **All comments must be resolved** |
| 67 | +- ✅ If new commits are pushed, previous approvals are dismissed (stale reviews) |
| 68 | + |
| 69 | +### 4. Merge |
| 70 | + |
| 71 | +```bash |
| 72 | +# Once approved: |
| 73 | +# - Click "Merge Pull Request" on GitHub |
| 74 | +# - Confirm merge |
| 75 | +# - Optional: Delete branch after merge |
| 76 | +``` |
| 77 | + |
| 78 | +--- |
| 79 | + |
| 80 | +## 🚨 What if I already pushed directly to main? |
| 81 | + |
| 82 | +### If you just pushed (and nobody has pulled): |
| 83 | + |
| 84 | +**Admins can revert:** |
| 85 | + |
| 86 | +```bash |
| 87 | +# 1. Identify the bad commit |
| 88 | +git log --oneline -5 |
| 89 | + |
| 90 | +# 2. Revert (creates new commit that undoes the changes) |
| 91 | +git revert <commit-hash> |
| 92 | +git push origin main |
| 93 | + |
| 94 | +# Or if there are multiple bad commits: |
| 95 | +git revert <commit-hash-1>..<commit-hash-n> |
| 96 | +git push origin main |
| 97 | +``` |
| 98 | + |
| 99 | +**Note:** Admins can push directly in emergencies, but should use this carefully. |
| 100 | + |
| 101 | +### If others have already pulled: |
| 102 | + |
| 103 | +**DO NOT use `git reset --hard` + force push** — it breaks everyone else's history. |
| 104 | + |
| 105 | +**Correct option:** |
| 106 | +1. Create PR with fix/revert |
| 107 | +2. Merge normally |
| 108 | + |
| 109 | +--- |
| 110 | + |
| 111 | +## 🔥 Emergencies (Admins Only) |
| 112 | + |
| 113 | +**Admins can bypass** protections in critical cases: |
| 114 | + |
| 115 | +**When it's acceptable:** |
| 116 | +- 🔥 Critical security hotfix |
| 117 | +- 🔥 Bug fix that blocks production |
| 118 | +- 🔥 Revert accidental commit (if nobody else has pulled) |
| 119 | + |
| 120 | +**Process:** |
| 121 | +1. Notify in the work group |
| 122 | +2. Explain why it's an emergency |
| 123 | +3. Make the direct change |
| 124 | +4. Document in CHANGELOG or commit message |
| 125 | + |
| 126 | +--- |
| 127 | + |
| 128 | +## 📋 Rules Summary |
| 129 | + |
| 130 | +| Action | Allowed | Requires | |
| 131 | +|--------|---------|----------| |
| 132 | +| Direct push to `main` | ❌ | - | |
| 133 | +| Force push to `main` | ❌ | - | |
| 134 | +| Create PR | ✅ | Nothing | |
| 135 | +| Merge PR | ✅ | 1 approval + resolved comments | |
| 136 | +| Delete `main` branch | ❌ | - | |
| 137 | +| Admin bypass | ⚠️ | Judgment (emergencies only) | |
| 138 | + |
| 139 | +--- |
| 140 | + |
| 141 | +## 🎯 Benefits |
| 142 | + |
| 143 | +- ✅ **Prevents accidents** (like the direct push to main that motivated this) |
| 144 | +- ✅ **Mandatory code review** (improves code quality) |
| 145 | +- ✅ **Clean history** (no force pushes that break git) |
| 146 | +- ✅ **Comments must be resolved** (discussions don't get left hanging) |
| 147 | +- ✅ **Protects production** (main is always in a deployable state) |
| 148 | + |
| 149 | +--- |
| 150 | + |
| 151 | +## ❓ FAQ |
| 152 | + |
| 153 | +### What if I need to make an urgent change? |
| 154 | + |
| 155 | +**Option 1 (preferred):** Quick PR + request urgent review in the group. |
| 156 | + |
| 157 | +**Option 2 (real emergency):** Admin pushes directly + notifies the team. |
| 158 | + |
| 159 | +### Can I approve my own PR? |
| 160 | + |
| 161 | +Yes, but it **requires at least 1 approval from another person** before merge. |
| 162 | + |
| 163 | +### What happens if I accidentally push to main? |
| 164 | + |
| 165 | +GitHub rejects it: |
| 166 | +``` |
| 167 | +! [remote rejected] main -> main (protected branch hook declined) |
| 168 | +``` |
| 169 | + |
| 170 | +Simply create a PR with those changes. |
| 171 | + |
| 172 | +### Are CI tests mandatory? |
| 173 | + |
| 174 | +Not currently. Can be enabled later by adding `required_status_checks`. |
| 175 | + |
| 176 | +--- |
| 177 | + |
| 178 | +## 📚 Resources |
| 179 | + |
| 180 | +- [GitHub Branch Protection Docs](https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/managing-protected-branches/about-protected-branches) |
| 181 | +- [Pull Request Best Practices](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests) |
| 182 | + |
| 183 | +--- |
| 184 | + |
| 185 | +**Updated:** 2026-03-26 |
| 186 | +**By:** Mostronator (automation) |
| 187 | +**Reason:** Prevent accidental pushes to main |
0 commit comments