How can I fix the fact that I'm working on the wrong branch

So, I wanted to work on a branch with a name directory-layout, but it turns out I'm working on a branch called master. This is problem.

I have not completed git add .andgit commit -m "I've made a horrendus mistake I'm sorry"

What should I do to add changes to another (or new) branch and why?

+4
source share
2 answers

If this branch is new, you can simply create it:

git checkout -b anewbranch
git add .
git commit -m "message"

But if this branch is old, you can cherry-pick commit instead :

  • add and commit
  • go to the old branch
  • git cherry grip master

Then reset go to its previous commit

git checkout master
git reset --hard @~1

git stash, .

+4

.

  git checkout -b <newbranch> 
+2

Source: https://habr.com/ru/post/1681753/


All Articles