Git Create New Branch with Local Changes |Video upload date:  · Duration: PT2M30S  · Language: EN

Create a new Git branch when local changes exist and preserve work during branch switch and reapply changes safely

So you have half finished code that you are not ready to show the world and you need a new branch. Welcome to the delightful world of version control anxiety. This guide shows how to move local changes into a fresh branch without losing work or inventing new swear words.

Save your local work

If your working tree is messy but you do not want to rewrite history try one of these two polite options. Stashing hides changes without adding a noisy commit. A quick local commit preserves a record so you can cherry pick or move it later.

git stash push -m "WIP"
# or
git add . && git commit -m "WIP"

Use stash for temporary experiments and small WIP commits when you want an explicit checkpoint. Both keep your files safe while you switch branches.

Create the new branch

Make the branch where this work actually belongs. Pick the newer command or the classic one. Both do the job and both will judge you equally if you named the branch feature123.

git switch -c new-branch
# or
git checkout -b new-branch

Move your work into the new branch

If you used a stash apply it now. If you made a local commit move it with cherry pick or by resetting and applying. Pick the option that matches your sense of order and the repo rules.

git stash pop
# or, for a local commit
git cherry-pick COMMIT_HASH

Stash pop will try to apply and remove the stash in one go. Cherry pick will copy the commit into the new branch and leave the original where it was. Both are valid. Both deserve coffee.

When conflicts appear

Conflicts will show up when the saved changes touch the same lines as the branch. Resolve them like an adult. Use your diff tool or edit the files by hand. Then mark the fixes and finish the job.

git status
# resolve files, then
git add .
git commit -m "Resolve conflicts and apply WIP"

Finish up and share

Once the new branch holds your work and the repo is clean push it upstream if collaboration is needed. Set the upstream on the first push and move on with your life.

git push -u origin new-branch

Quick tips for less panic

  • Use clear stash messages so you do not end up guessing what WIP means two days later
  • Prefer small WIP commits instead of huge blobs of changes
  • Use git switch -c for clarity and to look like you read the docs
  • Test locally after applying changes before you push

Follow these steps and you will move local changes into focused branches with minimal drama. Your future self will thank you or at least be a little less angry.

I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!

This is a dedicated watch page for a single video.