0

I cloned the development branch from a gitlab repo into my local machine(window). After that I was supposed to create a new branch from this development branch by git checkout -b new_branch but I forgot to do that and I did all the changes inside the development branch itself. I just remember it while pushing(my bad).

Now I want to create new branch from this development branch and want to keep all these changes of the development branch(which are not pushed and should not be pushed) to this newly created branch. How can I do this ?

D_P
  • 802
  • 10
  • 32
  • Might be Regret Type 3: https://stackoverflow.com/questions/3528245/whats-the-difference-between-git-reset-mixed-soft-and-hard/59675191?r=SearchResults#59675191 – matt Oct 22 '20 at 04:54

1 Answers1

1

This is a very common mistake people make when using Git, and it isn't just beginners who do this by accident. Assuming you haven't yet committed your work, you might even be able to just checkout a new branch:

# from development
git checkout -b new_branch

Then, commit your work and you should be good to go. If, for some reason, you can't create a new branch from development, another easy option would be to just stash your work, then create the branch and apply the stash:

# again, from development
git stash
git checkout -b new_branch
# from new_branch
git stash apply

Again commit your work when it is done to this new branch.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360