-2

I accidentally started working on a merged branch, now I want go back to develop get the updated code and then create a new branch. Is it possible to do so, or is there a workaround?

2 Answers2

0

if you wanna undo commits check this: How do I undo the most recent local commits in Git?

if you just want to change branch and create a new branch run this in terminal:

git checkout -b (write the name you want)

by running this you will create a new branch and also will switch to it.

Eliftch
  • 218
  • 1
  • 4
  • 13
  • if I create a new branch from this merged feature branch that will mess up the workflow. If my work was limited to a couple of files I could maybe copy those changes, stash my code and then got to develop and then create a new branch, but I've got a lot of changes that I accidentally started writing in this branch (no commits done). – mohammad-23 Jul 24 '20 at 20:11
  • 1
    just stash and the pop in new branch https://stackoverflow.com/questions/37417792/apply-stash-to-different-branch – Alexan Jul 24 '20 at 20:29
0

Use the following commands:

git stash: It will stash your uncommited changes.

git checkout develop: Go to develop branch

git pull: Get the latest code

git checkout -b "new branch" : Create a new branch

git stash apply : It will add your uncommited changes made in the step 1

Chakreshwar Sharma
  • 2,571
  • 1
  • 11
  • 35