Skip to content
Fix Code Error

Create a branch in Git from another branch

March 13, 2021 by Code Error
Posted By: Anonymous

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.

Solution

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:

$ git checkout -b myFeature dev

Creates MyFeature branch off dev. Do your work and then

$ git commit -am "Your message"

Now merge your changes to dev without a fast-forward

$ git checkout dev
$ git merge --no-ff myFeature

Now push changes to the server

$ git push origin dev
$ git push origin myFeature

And you’ll see it how you want it.

Answered By: Anonymous

Related Articles

  • Why do git fetch origin and git fetch : behave differently?
  • Why call git branch --unset-upstream to fixup?
  • Why do I have to "git push --set-upstream origin "?
  • Checkout another branch when there are uncommitted…
  • Git workflow and rebase vs merge questions
  • Git - Pushing code to two remotes
  • Why does git perform fast-forward merges by default?
  • Git Using Remote Branch
  • How can I find the location of origin/master in git,…
  • Difference between git checkout --track…
  • Retrieve specific commit from a remote Git repository
  • How does origin/HEAD get set?
  • How do I make a Git commit in the past?
  • Setting up and using Meld as your git difftool and mergetool
  • Your configuration specifies to merge with the from…
  • What's the difference between "git reset" and "git…
  • What is a tracking branch?
  • git pull while not in a git directory
  • How can I switch to another branch in git?
  • Remove tracking branches no longer on remote
  • What is "git remote add ..." and "git push origin master"?
  • How to create the branch from specific commit in…
  • How to pull in changes from skeleton sub-repository…
  • What are the differences between git remote prune,…
  • How do I delete a Git branch locally and remotely?
  • How to fetch all Git branches
  • npm ERR! fetch failed status code 502
  • What's the difference between git clone --mirror and…
  • Change a Git remote HEAD to point to something…
  • What exactly does the "u" do? "git push -u origin…
  • Git merge with force overwrite
  • Git: Create a branch from unstaged/uncommitted…
  • Why did my Git repo enter a detached HEAD state?
  • Git submodule head 'reference is not a tree' error
  • In plain English, what does "git reset" do?
  • Git, How to reset origin/master to a commit?
  • How can I reconcile detached HEAD with master/origin?
  • Rebasing remote branches in Git
  • How can I move HEAD back to a previous location?…
  • Why does Git say my master branch is "already up to…
  • git remote prune – didn't show as many pruned…
  • Git push won't do anything (everything up-to-date)
  • “tag already exists in the remote" error after…
  • How can I delete all Git branches which have been merged?
  • Various ways to remove local Git changes
  • Homebrew install specific version of formula?
  • Git fetch remote branch
  • What is git tag, How to create tags & How to…
  • unable to deploy next js to azure
  • git lfs push to github failure on Ubuntu 18.04
  • Git push: "fatal 'origin' does not appear to be a…
  • Git push rejected after feature branch rebase
  • Git push error: "origin does not appear to be a git…
  • Git merge master into feature branch
  • git pull from master into the development branch
  • Why does Git tell me "No such remote 'origin'" when…
  • How do I rename both a Git local and remote branch name?
  • How do I clone a single branch in Git?
  • Does "git fetch --tags" include "git fetch"?
  • Check if pull needed in Git
  • Merge, update, and pull Git branches without using checkouts
  • How to track untracked content?
  • In Git, what is the difference between origin/master…
  • git bring some "older" changes to a new branch after…
  • How to recover stashed uncommitted changes
  • Git submodule update
  • How to list branches that contain a given commit?
  • git push says "everything up-to-date" even though I…
  • master branch and 'origin/master' have diverged, how…
  • Push on GIT and Bitbucket
  • Git branching: master vs. origin/master vs.…
  • How do you get git to always pull from a specific branch?
  • Remote branch is not showing up in "git branch -r"
  • How to clone ('fork') your own personal GitHub repo…
  • Why is Git better than Subversion?
  • Rename master branch for both local and remote Git…
  • fetch in git doesn't get all branches
  • Delete all local git branches
  • What's the difference between HEAD^ and HEAD~ in Git?
  • How to git reset --hard a subdirectory?
  • How do I add files and folders into GitHub repos?
  • Cleaning up old remote git branches
  • Is it safe to shallow clone with --depth 1, create…
  • How to clone all remote branches in Git?
  • Push git commits & tags simultaneously
  • git status shows modifications, git checkout --…
  • Git's famous "ERROR: Permission to .git denied to user"
  • Updates were rejected because the tip of your…
  • How do I 'overwrite', rather than 'merge', a branch…
  • Why does git say "Pull is not possible because you…
  • XMLHttpRequest cannot load ✘✘✘ No…
  • Recalculate merge conflicts (ie. how to generate…
  • Squash the first two commits in Git?
  • Git: Merge a Remote branch locally
  • Finding what branch a Git commit came from
  • Egit rejected non-fast-forward
  • How do you stop tracking a remote branch in Git?
  • What is the best (and safest) way to merge a Git…
  • How to retrieve a single file from a specific…
  • How to use terminal commands with Github?

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

How to initialize List object in Java?

Next Post:

Text-align class for inside a table

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

.net ajax android angular arrays aurelia backbone.js bash c++ css dataframe ember-data ember.js excel git html ios java javascript jquery json laravel linux list mysql next.js node.js pandas php polymer polymer-1.0 python python-3.x r reactjs regex sql sql-server string svelte typescript vue-component vue.js vuejs2 vuetify.js

  • you shouldn’t need to use z-index
  • No column in target database, but getting “The schema update is terminating because data loss might occur”
  • Angular – expected call-signature: ‘changePassword’ to have a typedeftslint(typedef)
  • trying to implement NativeAdFactory imports deprecated method by default in flutter java project
  • What should I use to get an attribute out of my foreign table in Laravel?
© 2022 Fix Code Error