Question

I have a new job however they use mercurial as their version control and most of my experience is with git. I try to learn mercurial but the way it does branching (even with extensions like bookmarks) just make absolutely no sense to me. Does anyone know of a way to use git locally but push to mercurial?

I have tried the hg-git plugin and have gotten to the point where I can commit in git and push those changes to a remote mercurial repo however the issue I am running into is that no matter what tutorial I have found, I can't seem to pull new changes from mercurial back into git (which makes the entire thing useless at this point). If you have a link on how to setup hg-git to work pushing to mercurial, please let me know of it.

The Solution (I think)

Base on the comments made by Lazy Badger, this is what I think will work : http://ryanzec.com/index.php/blog/details/9

Was it helpful?

Solution

Think some time, see alternative solution, same lopsided and crooked, but less pretentious (I hope) - 3 repos (2 Mercurial + 1 Git) in 3-tier architecture of chain

They have (local) names, used below:

  • Master (hg) - central Mercurial repo of company
  • Mediator (hg) - middleware for translating changesets, created as clone of Master
  • WorkHorse (git) - final workplace, empty at start

Mediator have setting almost identical (hg-git, bookmarks) to hg-repo from solution 1, except one detail in [paths] section of hgrc - will be two path in in: Master and WorkHorse in order to be able pull|push in both direction, with Master and WorkHorse

Workflow:

  • Mediator pull changes from Master, push to WorkHorse (changesets presented as is, without collapsing, contrary to solution 1)
  • All (almost? not sure about merges) work happens on WorkHorse
  • Mediator pull changes from WorkHorse, push to Master

OTHER TIPS

You can work with Mercurial end-point from git, but, unlike the inverse direction (hg -> git) you'll have to have both VCS and two repos on same location

  1. Install Mercurial
  2. Install hg-git extension for Mercurial
  3. Make sure you've enabled the Hg bookmark extension in your .hgrc
  4. Add to your .hgrc:

    [git]
    intree=1
    
  5. Clone your Mercurial repo

    hg clone ... repo
    
  6. Go to repo

    cd repo
    
  7. Create a local bookmark tracking your Mercurial default branch - this is what will be exported to your Git

    hg bookmark hg/default -r default
    
  8. Export to the git repo

    hg gexport
    
  9. Configure Hg to ignore the Git repo

    echo ".git" >> .hg/hgignore
    
  10. Configure Git to ignore the Hg repo

    echo ".hg*" >> .git/info/exclude
    
  11. Configure Git to ignore the same things as Mercurial

    git config core.excludesfile `pwd`/.hg/hgignore
    
  12. Have your master branch track the exported Hg default branch

    git branch --track master hg/default
    git reset --hard
    
  13. Work and commit to Git as usual

  14. Export your changes to Hg

    hg gimport
    
  15. Push all to the world

    hg push
    

For every-day-work repeat steps 13-15

PS: Work from HG to Git produces a lot less actions and headache

Nowadays, there is a new git-remote-hg extension that does what you need. It seems to be the counterpart to Hg-Git plugin. See http://felipec.wordpress.com/2012/11/13/git-remote-hg-bzr-2/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top