-1

I've got a series of commits in default branch of my fork waiting for review and merge upstream. Now I need to fill a separate bug fix and I want to return to the original branch point between my repo and remote. I can look through the changelog manually and hg up to the revision, but it is inconvenient.

Is there a command that does this - creates new branch at the last commit available from upstream and switches to it?

I need this command, but for Mercurial https://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/git-new-branch.html

anatoly techtonik
  • 19,847
  • 9
  • 124
  • 140
  • You don't need to take any special measures in order to create a branch. Just update to the revision you want your branch based-on and start committing. There's no concept of 'remote' other than what `hg outgoing` and `hg incoming` give you. Attach (local) bookmarks to revisions you want to quickly jumt to; bookmarks are convenient transient markers which DO NOT become part of history. – planetmaker Sep 06 '16 at 12:00
  • @planetmaker `just update` doesn't work in this case, because I don't know the revision number I need to update to. – anatoly techtonik Sep 06 '16 at 20:04

1 Answers1

1

hg update is quite powerful, I recommend you look into the REVSET help page, which details the operators and predicates you can use to specify the desired revision.

For instance, hg update -r parents(first(outgoing(UPSTREAM))) should update to the parent of the oldest changeset that has not yet been pushed to UPSTREAM, which seems to be what you are asking for. This will work when the oldest unpushed changeset has a single parent (i.e. it is not the result of a merge).

If it has two parents, you can use hg update -r p1(first(outgoing(UPSTREAM))) or hg update -r p2(first(outgoing(UPSTREAM))) instead, but you'll need to know which parent you want to start the branch at.

You can also create an alias if you wish, if you put the following in your Mercurial config file:

[alias]
newbranch = hg update -r parents(first(outgoing(UPSTREAM)))

The newbranch part is whatever you want the command to be.

Sigve Kolbeinson
  • 1,133
  • 1
  • 7
  • 16