5

I have come to the git party a little late and I have a simple problem.

I have three feature experiments in development that are currently on my master branch. The features could be called postits, auth, and uploads.

When I do git status on my master branch, I get a list of ~10 entries in 'changed but not updated' and ~15 in 'untracked files'. All these entries belong to one of the three feature experiments.

How can I move these entries into three new feature branches so I can have a clean working directory again?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
sscirrus
  • 55,407
  • 41
  • 135
  • 228

1 Answers1

6
$ git checkout -b postits     # create postits branch based on the current master
$ git add X Y Z               # add your parts, maybe with -p to get parts of files
$ git commit                  # commit to postits branch
$ git checkout -b auth master # make branch based on master (not including postits)
$ # etc
Danica
  • 28,423
  • 6
  • 90
  • 122
  • 2
    you can do `git checkout -b auth master` – manojlds Dec 10 '11 at 00:31
  • @Dougal - This is a long time ago but... how can you create a **clean** new branch with only X,Y,Z? My master has a mass of files in it (tracked and untracked) and when I created `postits` like you said, `postits` is now full of other files I don't need. When I try `git checkout master` it stops me. How can I clean these out of postits or not copy them in the first place? – sscirrus Jun 07 '12 at 06:46
  • I think you can do this with `git stash -u` (assuming you have a fairly recent git; otherwise, `git add` all the untracked files before you `stash`). First stash so your working directory is clean, then you can switch branches cleanly and `git stash apply`, `git reset HEAD`, `git add` to get each branch how you want it. – Danica Jun 07 '12 at 18:12