1

If so, what is the command for that?

Thanks so much SO community!

Trip
  • 26,756
  • 46
  • 158
  • 277

3 Answers3

5

If you have not committed:

git checkout -b newbranch; git commit

If you have committed:

git checkout -b newbranch

If you have committed and not pushed and want to remove them from the old branch:

git checkout -b newbranch; git checkout oldbranch; git reset --hard HEAD^

If you have committed and pushed and want to remove them from the old branch:

git checkout -b newbranch; git checkout oldbranch; git revert HEAD

I strongly recommend reading the Pro Git book. http://progit.org

Seth Robertson
  • 30,608
  • 7
  • 64
  • 57
  • Right on! Thanks a million bazillion Seth Robertson. – Trip May 28 '11 at 00:17
  • Those last two could use `git branch newbranch` (create branch without switching to it) instead of `git checkout -b newbranch; git checkout oldbranch`. – Chris Johnsen May 28 '11 at 04:28
0

SO to the rescue Git for beginners: The definitive practical guide

Community
  • 1
  • 1
Fredrik Pihl
  • 44,604
  • 7
  • 83
  • 130
0

It seems you already have commited changes that you want to commit again, but on another branch. Then you are looking for git cherry-pick

rtn
  • 127,556
  • 20
  • 111
  • 121