Explore Courses Blog Tutorials Interview Questions
+3 votes
in DevOps and Agile by (19.4k points)
edited by

I have two branches: master and dev

I want to create a "feature branch" from the dev branch.

Currently, on the branch dev, I do:

$ git checkout -b myfeature dev

... (some work)

$ git commit -am "blablabla"

$ git push origin myfeature

But, after visualizing my branches, I got:




I mean that the branch seems ff merged, and I don't understand why...

What I'm doing wrong?

Can you explain to me please how you branch off from another branch and push back to the remote repository for the feature branch?

All that in a branching model like the one described here.


1 Answer

+3 votes
by (27.5k points)
selected by
Best answer

First, create NewFeature branch off dev 

$ git checkout -b NewFeature dev

Now once you are done with your work perform git commit. 

$ git commit -am "Your commit message"

Next step would be to merge your changes to dev without a fast-forward

$ git checkout dev

$ git merge --no-ff NewFeature

That's it all you need to do now is push changes to the server

$ git push origin dev

$ git push origin NewFeature

git create branch from branch - how to create a branch in Git from another branch?
by (5.8k points)
Great solution. Thanks

Browse Categories