How to create a new branch and move the existing code there

Say I'm starting to work on a clear branch master- no changes to commit. Make some local changes, but understand that these changes should be separate branchinstead master.

Is there a way to move so that it changes to separate a new one branchand translate it masterinto status no changes to commit?

EDIT

According to the accepted answer on git branching - how to make the current master a branch and then revert the master back to the previous version? ... After completing the steps, my wizard will still have the modified files. See the last comment 7 .

Am I missing something?

$ git branch                                   # 1. starting on master                                     
# On branch master
  nothing to commit, working directory clean


# On branch master                             # 2.modifying a file 
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   test.txt
#
no changes added to commit (use "git add" and/or "git commit -a")



$ git stash                                    # 3. stashing changes
Saved working directory and index state WIP on master: 393bfad initial commit
HEAD is now at 393bfad initial commit
$ git status
# On branch master
nothing to commit, working directory clean


$ git checkout -b experiment                   # 4. creating new branch experiment 
Switched to a new branch 'experiment'


$ git stash pop                                # 5. pop staged changes in exper.
# On branch experiment
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   test.txt
#
no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/stash@{0} (16b6871d43f367edd03f59558eca4163cd1a2b2f)


$ git checkout master                           #6. going back to master
M   test.txt
Switched to branch 'master'
git status
# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   test.txt                #7. in master test.txt is still modified !!!
+4
4

git stash pop . master, .

$ git stash pop
$ git commit -m "Committing changes to branch experiment"
$ git checkout master

. (.. ), :

$ git checkout -b experiment
$ git add test.txt
$ git commit -m 'Commit message'
$ git checkout master

stash/pop , "" , , . .

+4

git stash git

+3

( git, ), stashing (http://git-scm.com/book/en/Git-Tools-Stashing) , .

git stash
git stash branch testchanges
0

, git stash. ( ) git stash, . :

  • .
  • . ( !)
  • , .
  • git branch -m feature-xy.
  • - , , git pull --rebase, .
  • , : git push -u feature-xy:feature-xy ( -u, .)
  • To get a local clean master, just check it out: git checkout master(Since there is no longer a local master, git will create a new one from the upstream.)
-1
source

All Articles