Move develop changes to a new feature branch

For my project I use git-flow. I have master and develop branch synchronized with remote-repo
Usually for all changes I create a feature branch, edit the files, commit the changes on the feature branch and close the branch with a merge in develop.

But sometimes I forget to create a feature branch and I edit files directly in develop. How can I move the canges in a new feature branch?

  • Git sparse checkout for simple web deployment
  • understanding git fetch then merge
  • How to configure Brackets as git core.editor in Windows
  • What are the differences between “git commit” and “git push”?
  • CMake 3.2.2 and Eclipse 4.5.1 CDT 8.0
  • Why does git ls-files --ignore require exclude patterns?
  • how to apply a git patch as if the author committed to my repo?
  • Elastic Beanstalk, Git and AWS Tools: How to clone repository to another workstation
  • Interactive rebase of a branch with its point of divergence from master
  • Switching Git branches inside an Android Repo project
  • What are currently the problems with Git on Windows
  • Git Error; RPC failed; result=22, HTTP code = 401
  • 4 Solutions collect form web for “Move develop changes to a new feature branch”

    If you’ve already made the commit to develop, and your history looks like this:

    A---B---C---D develop

    Here, C is the last correct commit on develop, and D should have been committed to a feature branch. Do the following (while on develop):

    git branch feature      # creates feature branch pointing at D
    git reset --hard C      # or HEAD^, HEAD~1, etc - resets develop back to C

    This will result in:

    A---B---C develop
              D feature

    This will also work well if you’ve made more than one commit, as you can substitute whichever commit reference you need to reset develop back to in the second command.

    Assuming you already committed these changes locally and haven’t pushed yet, you can use a soft reset:

    git reset --soft HEAD~1
    git checkout feature
    git commit

    Just replace the 1 in git reset --soft HEAD~1 with the number of commits you want to soft reset.

    you can use git stash for putting the changes to a new branch, see git book

    So in master, after you made the changes (but didn’t add or commit them) you could do:

    git stash //stashes the changes
    git stash branch featurebranchname //creates a new branch and applies the stash to it

    You can cherry pick the changes to new branch.

    Git Baby is a git and github fan, let's start git clone.