Move develop changes to a new feature branch
For my project I use git-flow. I have
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
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
- how can I customize git's merge commit message?
- Git: committing to a tag and then merging commit to master
- How can I audit git rerere's resolutions?
- How can I merge local site with a staging remote
- Objective-Git Merge
- How to squash my git branch commits into the same branch without rebasing?
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:
C is the last correct commit on
D should have been committed to a feature branch. Do the following (while on
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.