GIT - Isolate new Feature from the master branch in a new branch and reset the master branch.

Asked

Viewed 171 times

3

I created a new Feature in the master branch and would like to isolate it in a new branch.

Also, after creating the new branch, I’d like to reset my local master branch to the remote master branch.

I created this new local branch, which turns out to be a copy of the master local branch (already including my Feature), now I don’t quite understand how to reset only my master site to look exactly like the remote master.

I need to do this in order to commit and push the master without changing the application in production with this new Feature, which is not yet completed.

I hope I have been clear, that my goal is only to give a reset on the master and not on the others.

Thank you.

  • You committed some commit in master with these changes?

  • Not yet. I started developing this Feature and I didn’t commit anymore. It was a mistake not to have isolated it in a new branch (that’s why I wanted to do it now). My remote master branch has nothing to do with this change.

  • So you just do one git checkout -b feature to create a new branch with Features from the master and commit from there. When to return to the branch master he will be as the remote master.

  • @Marcelodeandrade, I didn’t understand how my local master will look like the remote (returning to the remote master state). Is it because when commiting only the Feature branch the master site will lose the changes? I really didn’t understand this part.

  • Give a read on the answer.

1 answer

5


If you have not done any commit in his master branch, you can effect the git checkout -b feature to create a new branch with the changes made.

With that your master branch will be in accordance with the remote branch because all the changes made will belong to the branch Feature.

To understand, see the simulation on learngitbranching with the following commands:

  1. git branch feature
  2. git checkout feature
  3. git commit

Another example showing a commit on master branch after the Feature v inserir a descrição da imagem aqui

  • Perfect. That’s exactly what I needed to do.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.