Skip to content

Instantly share code, notes, and snippets.

@alex
Created March 31, 2017 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alex/93d7f4a2bf04e0ec8fd8bb9dc7af74b5 to your computer and use it in GitHub Desktop.
Save alex/93d7f4a2bf04e0ec8fd8bb9dc7af74b5 to your computer and use it in GitHub Desktop.
Challenges porting my git workflow to mercurial

Challenges porting my git workflow to mercurial

How I do in git

I want to work on a repo:

$ git clone https://github.com/pyca/cryptography
$ cd cryptography

Now I have a local repo, with master checked out, and master is tracking origin/master.

I want to work on a feature, so I create a local branch for doing some hacking:

$ git checkout -b sweet-feature-branch

Now I have sweet-feature-branch checked out, it's not tracking anything, and my current commit is the same as master.

Now I do some hacking, change some files, and make a commit:

$ git commit -am "lol computers"

Now I'm on sweet-feature-branch, and it is one commit ahead of master.

In working on my totally awesome feature, I realized that a few things need to be refactored, so I'm going to make a new branch for that.

$ git checkout master
$ git pull
$ git checkout -b cleanup-branch

I switch over to master, because I want to start working from there, do a quick pull to see if anything new happened on origin, and create a new branch on which to do my work.

I do more computer work and commit:

$ git commit -am "sweet refactor"

Now, in a Github pull request workflow, I'd push this to my fork, and create the PR:

$ git remote add alex https://github.com/alex/cryptography
$ git push -u alex cleanup-branch

I'm still on cleanup-branch, it is one commit ahead of master, and I'm now tracking alex/cleanup-branch. I go into my web browser, create a PR, and lets say it gets merged.

Now I want to flip back over to my sweet-feature-branch and finish up that work.

$ git checkout master
$ git pull
$ git branch -D cleanup-branch
$ git checkout sweet-feature-branch

Now I'm back on sweet-feature-branch, which still doesn't track anything, and which is one commit ahead and one commit behind.

Now I'll either rebase or merge master, which I do depends on how I'm feeling on any particular day (because I like squash merges, it largely doesn't matter).

$ git merge master

Maybe it merges cleanly, maybe I need to resolve conflicts, that's mostly orthogonal to the point of this.

Challenges in mercurial

$ hg clone https://hghub.com/pyca/cryptography
$ cd cryptography
$ hg bookmark sweet-feature-branch
$ hg ci -m "lol computers"
$ # I do not know how to `git checkout master` now.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment