git-move-existing-edits-to-a-new-branch-railway-site.md (5169B)
1 --- 2 title: "Git — Move Existing Edits to a New Branch (Railway Site)" 3 description: "git checkout -b my-new-branch" 4 category: git-workflow 5 tags: ["git-workflow"] 6 tools: [] 7 difficulty: intermediate 8 updated: "2026-08-10" 9 source: "vault:Git/Git — Move Existing Edits to a New Branch (Railway Site).md" 10 --- 11 # 1. Create a new branch AND switch to it immediately 12 # Your uncommitted edits travel with you automatically 13 git checkout -b my-new-branch 14 15 # 2. Now commit your edits on the new branch 16 git add . 17 git commit -m "Site edits — moved to own branch" 18 19 # 3. Push the new branch to GitHub 20 git push -u origin my-new-branch 21 ``` 22 23 > [!info]+ Command Breakdown 24 > 1. **`git checkout -b my-new-branch`**: Creates the new branch and switches to it in one step — crucially, all your uncommitted file changes come with you because they live in the working directory, not on any branch 25 > 2. **`git add .`**: Stages every modified file 26 > 3. **`git commit -m "..."`**: Locks your edits into the new branch's history 27 > 4. **`git push -u origin my-new-branch`**: Creates the branch on GitHub and sets it as the upstream — Railway can then be pointed at this branch 28 29 > [!success]+ Expected Result 30 > 1. `my-new-branch` exists on GitHub with all your edits committed 31 > 2. `main` is unchanged — still matches the original forked repo 32 > 3. Railway can be configured to deploy from `my-new-branch` 33 34 --- 35 36 ## Scenario B — Edits Are Already Committed on Main 37 38 *You already ran `git commit` — the changes are in `main`'s history* 39 40 ```bash 41 # 1. Create a new branch at the current point in history 42 # This copies main's current state (including your commits) into the new branch 43 git checkout -b my-new-branch 44 45 # 2. Push the new branch to GitHub 46 git push -u origin my-new-branch 47 48 # 3. Now go back to main and strip your commits off it 49 git checkout main 50 51 # 4. Reset main back to match the original remote (before your edits) 52 git reset --hard origin/main 53 ``` 54 55 > [!info]+ Command Breakdown 56 > 1. **`git checkout -b my-new-branch`**: Creates a new branch that starts from exactly where `main` currently is — all your committed edits are included 57 > 2. **`git push -u origin my-new-branch`**: Pushes the new branch to GitHub **before** touching `main` — your work is safely backed up remotely 58 > 3. **`git checkout main`**: Switches back to main so you can clean it up 59 > 4. **`git reset --hard origin/main`**: Forces your local `main` to exactly match what GitHub's `main` looks like — effectively removing your local commits from it 60 61 > [!warning]+ Do Step 2 Before Step 4 62 > Push `my-new-branch` to GitHub **first**. Once you reset `main`, those commits are gone from `main` locally. They are safe on `my-new-branch` but only if you pushed it first. 63 64 > [!success]+ Expected Result 65 > 1. `my-new-branch` on GitHub contains all your site edits 66 > 2. `main` is clean — matches the original forked repo 67 > 3. No merging has occurred — the two branches are fully independent 68 69 --- 70 71 ## Pointing Railway at Your New Branch 72 73 > [!tip]+ Railway Deployment Branch 74 > 1. Go to your project in [Railway](https://railway.app/) 75 > 2. Navigate to **Settings → Source** 76 > 3. Change the deployment branch from `main` to `my-new-branch` 77 > 4. Railway will now build and deploy from your edits branch 78 > 5. `main` can remain as your clean baseline / fallback 79 80 --- 81 82 ## Quick Reference — Your Exact Workflow 83 84 ```bash 85 # ── CHECK WHERE YOU ARE ─────────────────────────────── 86 git status # See uncommitted changes 87 git log --oneline -5 # See last 5 commits on current branch 88 89 # ── SCENARIO A (uncommitted edits) ─────────────────── 90 git checkout -b my-new-branch # Move edits to new branch 91 git add . # Stage everything 92 git commit -m "My site edits" # Commit on new branch 93 git push -u origin my-new-branch # Push to GitHub 94 95 # ── SCENARIO B (already committed on main) ──────────── 96 git checkout -b my-new-branch # Branch off current main 97 git push -u origin my-new-branch # Push new branch FIRST (safety) 98 git checkout main # Go back to main 99 git reset --hard origin/main # Strip your commits from main 100 101 # ── VERIFY EVERYTHING LOOKS RIGHT ──────────────────── 102 git branch -a # See all branches 103 git log --oneline -5 # Check commit history on current branch 104 git checkout my-new-branch # Switch to your edits branch to confirm 105 ``` 106 107 --- 108 109 ## References 110 111 1. [Git Official Documentation](https://git-scm.com/doc) 112 2. [git-checkout — Git Reference](https://git-scm.com/docs/git-checkout) 113 3. [git-reset — Git Reference](https://git-scm.com/docs/git-reset) 114 4. [Railway Docs — Deployments](https://docs.railway.app/deploy/deployments) 115 5. [GitHub Docs — About Branches](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-branches) 116 117 --- 118 119 #Git #GitHub #Railway #BranchManagement #Workflow #SiteDeployment