0

My git status shows the following,I want to create a new branch and transfer over these uncomiited changes to that branch..how can I do that?

<prompt>git status
# Not currently on any branch.
# 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:   DATA/code/inc/sirApi.h
#       modified:   DATA/code/src/pe/include/miloSession.h
#       modified:   DATA/code/src/pe/milo/miloProcessSmeReqMessages.c
#       modified:   DATA/SME/src/sac/sacApiRoam.c
#       modified:   DATA/SME/src/sac/sacInsideApi.h
Kalle Pokki
  • 4,939
  • 2
  • 17
  • 18
user1934146
  • 2,905
  • 10
  • 25
  • 25
  • possible duplicate of ["Git: Create a branch from unstaged/uncommited changes on master"](http://stackoverflow.com/q/2569459/), ["Git - Create a branch with current changes"](http://stackoverflow.com/a/3899660), ["Git commit all files"](http://stackoverflow.com/q/4571106) – outis Jan 17 '13 at 08:20

2 Answers2

1

Try this:

git checkout -b newbranch
git add [your files]
git commit -m'Your message'

If you want to commit all your files, you can run

git checkout -b newbranch 
git commit -a -m'Your message'
aalbagarcia
  • 1,019
  • 7
  • 20
  • @ aag -is there a way I can add all of these files in one shot rather than one by one – user1934146 Jan 17 '13 at 07:00
  • is that git add -A - ..there is a "-" at the end – user1934146 Jan 17 '13 at 07:10
  • I find `git add .` the most intuitive form if I want to add everything in my working directory. – Kalle Pokki Jan 17 '13 at 07:16
  • @user1934146: No. The – is added by Stack Overflow at the end of the comment. Look at the previous comment to compare :) – me_and Jan 17 '13 at 14:22
  • `git add .` does not add deleted files to the staging area, while `git add -A` does. Just in case you didn't know. Have a look [at the manual page](http://www.kernel.org/pub/software/scm/git/docs/git-add.html), options -A and -u – aalbagarcia Jan 17 '13 at 20:18
0

Use

git checkout -b <new-branch> <start-point>

Where new-branch is the name of the branch you want to create, and start-point the sha1 where you want the new branch to start from. Since you are detached, I think it's best to explicitly state the starting point so you are sure where your branch starts from.

Kalle Pokki
  • 4,939
  • 2
  • 17
  • 18