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?

  • remove a file with dashes from git
  • Git pull is always invoking merge
  • When does git pull cause merge between multiple branches?
  • Git - Merge vs rebase
  • Git External Resource into Dev Branch Automatically
  • Patch deployment - git doesn't fetch the latest remote commit
  • Git merge didn't merge two files only?
  • Merging only selected changes in git
  • 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.