How can I move all my modification to a branch

I create a working repository in HG.
And I have modified some files.

How can i move my all my modification to a branch (a branch that I have not created)?
(kind of ‘git stash’ and the move the stash away change to a branch. Actually, I am not sure how I can do that in git either. If you know, I appreciate if you can tell me in git as well)

Thank you.

  • Why does Git not store the branch name as part of the commit?
  • Using a git subrepo which has ANOTHER git subrepo in a mercurial repository, is this possible?
  • Why is my Git repository so much larger than Mercurial version?
  • What's the Git approach to publish a patch queue?
  • What makes some version control systems better at merging?
  • interoperation between mercurial and subversion
  • Is it possible and how “Giving credit for a change” for Mercurial/Git as in Bazaar?
  • Mercurial: Back out public changesets and reapply to new public branch?
  • 2 Solutions collect form web for “How can I move all my modification to a branch”

    First check to make sure that neither the ShelveExtension nor AtticExtension do exactly what you want.

    If you’re doing it manually in mercurial I’d avoid a named branch, and just use another head. If for example, you already made the changes you want to “put away” for a little bit.

    hg commit -m 'working on Xxx' # you created a new tip
    hg update -r -2               # switch to the revision before the tip

    and now just start working there. You can find that anonymous branch later with hg heads and merge it in with hg merge.

    For Git, if you have not yet committed your files, just type:

    $ git checkout -b newbranch
    $ git commit -m "a message"

    Every file staged at this point will be committed in the new branch.

    For Mercurial, branches are not names by default, and a new branch only occurs (within one repo) if a commit has a parent which has already a child commit:

    enter image description here

    But you can create a new branch name for your next commit:

    hg branch branch-1          # start a new branch name
                                # modify something in the repository
    hg commit -m "branch-1"     # the changeset has branch name "branch-1"

    (See also a Guide to branching in Mercurial, and Git & Mercurial models)

    Git Baby is a git and github fan, let's start git clone.