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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Git Sync Guide: Merging Local Branch to Multiple Remotes
|
| 2 |
+
|
| 3 |
+
This guide documents the process for merging a local branch to multiple remote repositories and pushing the changes.
|
| 4 |
+
|
| 5 |
+
## Overview
|
| 6 |
+
|
| 7 |
+
When working with multiple remote repositories (like different deployment environments), you may need to sync your local changes to all of them. This guide shows how to merge a local branch to multiple remote `main` branches safely.
|
| 8 |
+
|
| 9 |
+
### HuggingFace Space Configuration
|
| 10 |
+
|
| 11 |
+
Each HuggingFace space copy uses **identical code** with only these differences:
|
| 12 |
+
|
| 13 |
+
1. **README.md** - Different titles/descriptions to distinguish spaces on HuggingFace
|
| 14 |
+
2. **Environment Variable `appName`** - Determines which configuration to use:
|
| 15 |
+
- `NCSLM_LPD` - Uses config from `NCSLM_LPD/assistant_config.py`
|
| 16 |
+
- `SEL` - Uses config from `SEL/assistant_config.py`
|
| 17 |
+
- `SEL_COACH` - Uses config from `SEL_COACH/assistant_config.py`
|
| 18 |
+
|
| 19 |
+
This allows multiple deployments of the same application with different behaviors/configurations while maintaining a single codebase.
|
| 20 |
+
|
| 21 |
+
## Branching Strategy
|
| 22 |
+
|
| 23 |
+
Our development workflow follows a structured branching strategy:
|
| 24 |
+
|
| 25 |
+
### Deployment Flow
|
| 26 |
+
```
|
| 27 |
+
main (local development)
|
| 28 |
+
↓
|
| 29 |
+
├── origin-sel/main (main-sel)
|
| 30 |
+
└── origin-sel-coach/main (main-sel-coach)
|
| 31 |
+
```
|
| 32 |
+
|
| 33 |
+
```
|
| 34 |
+
origin-sel/main (main-sel)
|
| 35 |
+
↓
|
| 36 |
+
├── origin-sel-ch1/main
|
| 37 |
+
├── origin-sel-ch2/main
|
| 38 |
+
└── origin-sel-ch3/main
|
| 39 |
+
```
|
| 40 |
+
|
| 41 |
+
### Complete Workflow
|
| 42 |
+
1. **Development Phase**: Work and commit changes in `main` branch
|
| 43 |
+
2. **Deployment Phase**: Merge `main` into:
|
| 44 |
+
- `origin-sel/main` (tracked as `main-sel` locally)
|
| 45 |
+
- `origin-sel-coach/main` (tracked as `main-sel-coach` locally)
|
| 46 |
+
3. **Deployment Phase 2**: Use `origin-sel/main` (`main-sel`) to sync to channel remotes: (these copies are for concurrent use cases)
|
| 47 |
+
- `origin-sel-ch1/main`
|
| 48 |
+
- `origin-sel-ch2/main`
|
| 49 |
+
- `origin-sel-ch3/main`
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
## Prerequisites
|
| 53 |
+
|
| 54 |
+
- Git repository with multiple configured remotes
|
| 55 |
+
- Local branch with changes to sync
|
| 56 |
+
- Write access to all target remotes
|
| 57 |
+
|
| 58 |
+
## Process Workflow
|
| 59 |
+
|
| 60 |
+
### 1. Check Current Status
|
| 61 |
+
|
| 62 |
+
First, verify your current branch and git status:
|
| 63 |
+
|
| 64 |
+
```bash
|
| 65 |
+
git status
|
| 66 |
+
git branch -a
|
| 67 |
+
```
|
| 68 |
+
|
| 69 |
+
### 2. Fetch Latest Changes
|
| 70 |
+
|
| 71 |
+
Update all remote tracking branches:
|
| 72 |
+
|
| 73 |
+
```bash
|
| 74 |
+
git fetch origin-sel && git fetch origin-sel-coach
|
| 75 |
+
git fetch origin-sel-ch1 && git fetch origin-sel-ch2 && git fetch origin-sel-ch3
|
| 76 |
+
```
|
| 77 |
+
|
| 78 |
+
### 3. Merge to Each Remote (Repeat for each target remote)
|
| 79 |
+
|
| 80 |
+
For each remote repository, follow these steps:
|
| 81 |
+
|
| 82 |
+
#### Step 3.1: Create Local Tracking Branch
|
| 83 |
+
|
| 84 |
+
```bash
|
| 85 |
+
git checkout -B <local-branch-name> <remote>/<target-branch>
|
| 86 |
+
```
|
| 87 |
+
|
| 88 |
+
**Example:**
|
| 89 |
+
```bash
|
| 90 |
+
git checkout -B origin-sel-ch1-main origin-sel-ch1/main
|
| 91 |
+
```
|
| 92 |
+
|
| 93 |
+
**What this does:**
|
| 94 |
+
- `-B` flag creates a new branch or resets existing one
|
| 95 |
+
- Creates local branch tracking the remote branch
|
| 96 |
+
- Switches to the newly created branch
|
| 97 |
+
|
| 98 |
+
#### Step 3.2: Merge Your Local Branch
|
| 99 |
+
|
| 100 |
+
```bash
|
| 101 |
+
git merge <your-local-branch> --no-ff -m "Merge <your-local-branch> into <remote>/<target-branch>"
|
| 102 |
+
```
|
| 103 |
+
|
| 104 |
+
**Example:**
|
| 105 |
+
```bash
|
| 106 |
+
git merge main-sel --no-ff -m "Merge main-sel into origin-sel-ch1/main"
|
| 107 |
+
```
|
| 108 |
+
|
| 109 |
+
**What this does:**
|
| 110 |
+
- `--no-ff` creates a merge commit even if fast-forward is possible
|
| 111 |
+
- `-m` adds a descriptive commit message
|
| 112 |
+
- Merges your changes into the remote branch
|
| 113 |
+
|
| 114 |
+
#### Step 3.3: Push to Remote
|
| 115 |
+
|
| 116 |
+
```bash
|
| 117 |
+
git push <remote> <local-tracking-branch>:<target-branch>
|
| 118 |
+
```
|
| 119 |
+
|
| 120 |
+
**Example:**
|
| 121 |
+
```bash
|
| 122 |
+
git push origin-sel-ch1 origin-sel-ch1-main:main
|
| 123 |
+
```
|
| 124 |
+
|
| 125 |
+
## Complete Example
|
| 126 |
+
|
| 127 |
+
### Deployment Phase: Sync from `main` to variant remotes
|
| 128 |
+
|
| 129 |
+
First, sync your local `main` branch to the variant remotes:
|
| 130 |
+
|
| 131 |
+
```bash
|
| 132 |
+
# Fetch latest changes from variant remotes
|
| 133 |
+
git fetch origin-sel && git fetch origin-sel-coach
|
| 134 |
+
|
| 135 |
+
# Sync to origin-sel/main (main-sel)
|
| 136 |
+
git checkout -B main-sel origin-sel/main
|
| 137 |
+
git merge main --no-ff -m "Merge main into origin-sel/main"
|
| 138 |
+
git push origin-sel main-sel:main
|
| 139 |
+
|
| 140 |
+
# Sync to origin-sel-coach/main (main-sel-coach)
|
| 141 |
+
git checkout -B main-sel-coach origin-sel-coach/main
|
| 142 |
+
git merge main --no-ff -m "Merge main into origin-sel-coach/main"
|
| 143 |
+
git push origin-sel-coach main-sel-coach:main
|
| 144 |
+
|
| 145 |
+
# Return to main branch
|
| 146 |
+
git checkout main
|
| 147 |
+
```
|
| 148 |
+
|
| 149 |
+
### Deployment Phase 2: Sync from `main-sel` to channel remotes
|
| 150 |
+
|
| 151 |
+
Here's a complete example for syncing `main-sel` branch to three remotes:
|
| 152 |
+
|
| 153 |
+
```bash
|
| 154 |
+
# Switch to main-sel branch
|
| 155 |
+
git checkout main-sel
|
| 156 |
+
|
| 157 |
+
# Fetch latest changes
|
| 158 |
+
git fetch origin-sel-ch1 && git fetch origin-sel-ch2 && git fetch origin-sel-ch3
|
| 159 |
+
|
| 160 |
+
# Sync to origin-sel-ch1
|
| 161 |
+
git checkout -B origin-sel-ch1-main origin-sel-ch1/main
|
| 162 |
+
git merge main-sel --no-ff -m "Merge main-sel into origin-sel-ch1/main"
|
| 163 |
+
git push origin-sel-ch1 origin-sel-ch1-main:main
|
| 164 |
+
|
| 165 |
+
# Sync to origin-sel-ch2
|
| 166 |
+
git checkout -B origin-sel-ch2-main origin-sel-ch2/main
|
| 167 |
+
git merge main-sel --no-ff -m "Merge main-sel into origin-sel-ch2/main"
|
| 168 |
+
git push origin-sel-ch2 origin-sel-ch2-main:main
|
| 169 |
+
|
| 170 |
+
# Sync to origin-sel-ch3
|
| 171 |
+
git checkout -B origin-sel-ch3-main origin-sel-ch3/main
|
| 172 |
+
git merge main-sel --no-ff -m "Merge main-sel into origin-sel-ch3/main"
|
| 173 |
+
git push origin-sel-ch3 origin-sel-ch3-main:main
|
| 174 |
+
```
|
| 175 |
+
|
| 176 |
+
## Cleanup
|
| 177 |
+
|
| 178 |
+
After successful sync, clean up temporary branches:
|
| 179 |
+
|
| 180 |
+
```bash
|
| 181 |
+
# Return to original branch
|
| 182 |
+
git checkout main-sel
|
| 183 |
+
|
| 184 |
+
# Delete temporary tracking branches
|
| 185 |
+
git branch -D origin-sel-ch1-main origin-sel-ch2-main origin-sel-ch3-main
|
| 186 |
+
```
|
| 187 |
+
|
| 188 |
+
## Key Commands Explained
|
| 189 |
+
|
| 190 |
+
| Command | Purpose |
|
| 191 |
+
|---------|---------|
|
| 192 |
+
| `git checkout -B` | Create/reset local branch and switch to it |
|
| 193 |
+
| `git merge --no-ff` | Create explicit merge commit |
|
| 194 |
+
| `git push remote local:remote` | Push local branch to remote branch |
|
| 195 |
+
| `git branch -D` | Force delete local branches |
|
| 196 |
+
|
| 197 |
+
## Safety Tips
|
| 198 |
+
|
| 199 |
+
1. **Always fetch first** - Ensure you have latest remote changes
|
| 200 |
+
2. **Use `--no-ff`** - Creates clear merge history
|
| 201 |
+
3. **Descriptive commit messages** - Document what you're merging
|
| 202 |
+
4. **Clean up afterwards** - Remove temporary branches
|
| 203 |
+
5. **Test in one remote first** - If unsure, test the process with one remote
|
| 204 |
+
|
| 205 |
+
## Troubleshooting
|
| 206 |
+
|
| 207 |
+
### Merge Conflicts
|
| 208 |
+
If you encounter merge conflicts:
|
| 209 |
+
```bash
|
| 210 |
+
# Resolve conflicts in your editor
|
| 211 |
+
git add <resolved-files>
|
| 212 |
+
git commit -m "Resolve merge conflicts"
|
| 213 |
+
git push <remote> <local-branch>:<target-branch>
|
| 214 |
+
```
|
| 215 |
+
|
| 216 |
+
### Failed Push
|
| 217 |
+
If push fails due to remote changes:
|
| 218 |
+
```bash
|
| 219 |
+
git fetch <remote>
|
| 220 |
+
git merge <remote>/<target-branch>
|
| 221 |
+
# Resolve any conflicts
|
| 222 |
+
git push <remote> <local-branch>:<target-branch>
|
| 223 |
+
```
|
| 224 |
+
|
| 225 |
+
### Undo Last Merge (if not pushed yet)
|
| 226 |
+
```bash
|
| 227 |
+
git reset --hard HEAD~1
|
| 228 |
+
```
|
| 229 |
+
|
| 230 |
+
## Alternative: Automation Scripts
|
| 231 |
+
|
| 232 |
+
For frequent use, you can create automation scripts:
|
| 233 |
+
|
| 234 |
+
### Script 1: Deployment Phase (main → variant)
|
| 235 |
+
|
| 236 |
+
Create `sync-to-variant.sh`:
|
| 237 |
+
|
| 238 |
+
```bash
|
| 239 |
+
#!/bin/bash
|
| 240 |
+
LOCAL_BRANCH=${1:-main}
|
| 241 |
+
echo "Syncing $LOCAL_BRANCH to variant remotes..."
|
| 242 |
+
|
| 243 |
+
# Fetch latest changes from variant remotes
|
| 244 |
+
git fetch origin-sel && git fetch origin-sel-coach
|
| 245 |
+
|
| 246 |
+
# Sync to origin-sel/main (main-sel)
|
| 247 |
+
echo "Syncing to origin-sel/main..."
|
| 248 |
+
git checkout -B main-sel origin-sel/main
|
| 249 |
+
git merge $LOCAL_BRANCH --no-ff -m "Merge $LOCAL_BRANCH into origin-sel/main"
|
| 250 |
+
git push origin-sel main-sel:main
|
| 251 |
+
|
| 252 |
+
# Sync to origin-sel-coach/main (main-sel-coach)
|
| 253 |
+
echo "Syncing to origin-sel-coach/main..."
|
| 254 |
+
git checkout -B main-sel-coach origin-sel-coach/main
|
| 255 |
+
git merge $LOCAL_BRANCH --no-ff -m "Merge $LOCAL_BRANCH into origin-sel-coach/main"
|
| 256 |
+
git push origin-sel-coach main-sel-coach:main
|
| 257 |
+
|
| 258 |
+
# Return to original branch
|
| 259 |
+
git checkout $LOCAL_BRANCH
|
| 260 |
+
echo "variant sync complete!"
|
| 261 |
+
```
|
| 262 |
+
|
| 263 |
+
**Usage:** `./sync-to-variant.sh` or `./sync-to-variant.sh main`
|
| 264 |
+
|
| 265 |
+
### Script 2: Deployment Phase 2 (main-sel → channels)
|
| 266 |
+
|
| 267 |
+
Create `sync-to-channels.sh`:
|
| 268 |
+
|
| 269 |
+
```bash
|
| 270 |
+
#!/bin/bash
|
| 271 |
+
LOCAL_BRANCH=${1:-main-sel}
|
| 272 |
+
REMOTES=("origin-sel-ch1" "origin-sel-ch2" "origin-sel-ch3")
|
| 273 |
+
|
| 274 |
+
echo "Syncing $LOCAL_BRANCH to channel remotes..."
|
| 275 |
+
|
| 276 |
+
# Switch to source branch
|
| 277 |
+
git checkout $LOCAL_BRANCH
|
| 278 |
+
|
| 279 |
+
# Fetch latest changes
|
| 280 |
+
git fetch origin-sel-ch1 && git fetch origin-sel-ch2 && git fetch origin-sel-ch3
|
| 281 |
+
|
| 282 |
+
for remote in "${REMOTES[@]}"; do
|
| 283 |
+
echo "Syncing to $remote..."
|
| 284 |
+
git checkout -B ${remote}-main ${remote}/main
|
| 285 |
+
git merge $LOCAL_BRANCH --no-ff -m "Merge $LOCAL_BRANCH into $remote/main"
|
| 286 |
+
git push $remote ${remote}-main:main
|
| 287 |
+
done
|
| 288 |
+
|
| 289 |
+
git checkout $LOCAL_BRANCH
|
| 290 |
+
git branch -D origin-sel-ch1-main origin-sel-ch2-main origin-sel-ch3-main
|
| 291 |
+
echo "Channel sync complete!"
|
| 292 |
+
```
|
| 293 |
+
|
| 294 |
+
**Usage:** `./sync-to-channels.sh` or `./sync-to-channels.sh main-sel`
|
| 295 |
+
|
| 296 |
+
### Script 3: Complete Deployment (both phases)
|
| 297 |
+
|
| 298 |
+
Create `full-deploy.sh`:
|
| 299 |
+
|
| 300 |
+
```bash
|
| 301 |
+
#!/bin/bash
|
| 302 |
+
LOCAL_BRANCH=${1:-main}
|
| 303 |
+
|
| 304 |
+
echo "=== Starting Full Deployment ==="
|
| 305 |
+
echo "Phase 1: Syncing $LOCAL_BRANCH to variant remotes..."
|
| 306 |
+
|
| 307 |
+
# Phase 1: Sync to variant
|
| 308 |
+
./sync-to-variant.sh $LOCAL_BRANCH
|
| 309 |
+
|
| 310 |
+
echo "Phase 2: Syncing main-sel to channel remotes..."
|
| 311 |
+
|
| 312 |
+
# Phase 2: Sync to channels
|
| 313 |
+
./sync-to-channels.sh main-sel
|
| 314 |
+
|
| 315 |
+
echo "=== Full Deployment Complete ==="
|
| 316 |
+
```
|
| 317 |
+
|
| 318 |
+
**Usage:** `./full-deploy.sh` or `./full-deploy.sh main`
|
| 319 |
+
|
| 320 |
+
### Setup Instructions
|
| 321 |
+
|
| 322 |
+
1. Create the scripts:
|
| 323 |
+
```bash
|
| 324 |
+
chmod +x sync-to-variant.sh sync-to-channels.sh full-deploy.sh
|
| 325 |
+
```
|
| 326 |
+
|
| 327 |
+
2. Place them in your project root or add to your PATH
|
| 328 |
+
|
| 329 |
+
3. Run as needed:
|
| 330 |
+
- Individual phases: `./sync-to-variant.sh` → `./sync-to-channels.sh`
|
| 331 |
+
- Complete deployment: `./full-deploy.sh`
|