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:
--**master**
------0-----0-----0-----0-----0
------------------------**dev**----**myfeature**
I mean that the branch seems ff merged, and I don't understand why...
What I'm doing wrong?
Can you explain 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.
If you want create a new branch from any of the existing branches in Git, just follow the options.
First change/checkout into the branch from where you want to create a new branch. For example, if you have the following branches like:
So if you want to create a new branch called "subbranch_of_b1" under the branch named "branch1" follow the steps:
Checkout or change into "branch1"
Now create your new branch called "subbranch_of_b1" under the "branch1" using the following command.
The above will create a new branch called subbranch_of_b1 under the branch branch1 (note that
branch1
in the above command isn't mandatory since the HEAD is currently pointing to it, you can precise it if you are on a different branch though).Now after working with the subbranch_of_b1 you can commit and push or merge it locally or remotely.
push the subbranch_of_b1 to remote
If you like the method in the link you've posted, have a look at Git Flow.
It's a set of scripts he created for that workflow.
But to answer your question:
Creates MyFeature branch off dev. Do your work and then
Now merge your changes to dev without a fast-forward
Now push changes to the server
And you'll see it how you want it.
Git 2.23 introduces
git switch
andgit restore
to split the responsibilities ofgit checkout
Creating a new branch from an existing branch as of git 2.23:
git switch -c my-new-branch
Switched to a new branch 'my-new-branch'
Take a look at this Github blog post explaining the changes in greater detail:
To create a branch from another branch in your local directory you can use following command.
For Example:
For creating a branch from another one can use this syntax as well:
It is a little shorter than "git checkout -b " + "git push origin "
Do simultaneous work on the
dev
branch. What happens is that in your scenario the feature branch moves forward from the tip of the dev branch, but the dev branch does not change. It's easier to draw as a straight line, because it can be thought of as forward motion. You made it to point A on dev, and from there you simply continued on a parallel path. The two branches have not really diverged.Now, if you make a commit on dev, before merging, you will again begin at the same commit, A, but now features will go to C and dev to B. This will show the split you are trying to visualize, as the branches have now diverged.
Versus