Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

8
  • 25
    if you've already committed: note the hash of the commit you made (use git show or git rev-parse HEAD), switch to the branch and then git cherry-pick followed by the commit hash.
    – araqnid
    Commented May 18, 2012 at 9:35
  • 7
    If committed, get hash of last commit. Checkout the branch you wish to be at, and git merge _hash_
    – Daniel
    Commented May 31, 2012 at 13:31
  • BE REALLY CAREFUL. IF YOU HAVE COMMITTED THE CHANGE and you follow these steps...You will see the message..."Your branch and origin/master have diverged". Commented Dec 21, 2012 at 18:13
  • 1
    @thinkanotherone If you have committed your changes already there would be nothing to stash and checking out a different branch is not the end of the world. The commit you just made is still there and you can merge it to that branch by using git merge <hash-of-the-commit-you-just-made>.
    – Erik B
    Commented Jul 8, 2013 at 13:38
  • This is risky in case you end up with merge conflicts, and you are a git beginner. I'd prefer babay's answer, because making a branch of your current point is a good first step to keep track of where your code is. Commented Jan 30, 2014 at 23:42