37

30

How do I create a branch? How do I merge that with trunk?

flag

7 Answers

40

One of the best things about DVCS in general is that branching actually works really well. Branching works well because merging works well. This kind of makes sense to anyone who has used Subversion or most other centralized version control systems. It's never the branching that's the problem; it's that gigantic scary merge back to trunk. Sort of like that adage, "it's not the fall that kills you, it is the sudden stop at the end." But I digress...

There are generally two reasons to create branch repositories in Kiln:

  1. You want to work on a feature, but you don't want to impact other developers working in your "trunk" repository.
  2. You want to create a long-running branch for yourself or another developer (workspace). The workspace allows you to work without disrupting anything that is going on in the "trunk" repository. This facilitates the "review everything before it goes into trunk" code-review process.

To branch in Kiln, you need to be logged into the Kiln web interface and browsing your repositories. Each repository has a small context menu marked by the blue arrow, and from that menu you can create a branch repository:

Create a branch

You just need to give the branch a name. Kiln will copy the contents and history of the repository to the new branch.

Branch created

It is important to reiterate here that the branch you just created is actually a full-fledged repository. You work with it just like you would any other repository. That starts with cloning. When I am working in a branch, I usually just move my copy of the "trunk" repository out of the way by renaming the folder on my machine (e.g., kiln -> kiln-trunk), and then clone the branch repository to the old trunk location. That way I don't have to change anything in my development environment.

> hg clone http://your.fogbugz.com/kiln/repo/my/kiln/branch kiln

Now you're ready to start working and making changes. As always, you should commit your changes locally and then push them to the server. This acts as a backup, plus it allows you to collaborate with your teammates by all cloning/pulling/pushing from the branch repository, if desired. While you are working in the branch repository, you can make whatever changes you need without fear of destabilizing the development work that is continuing in the "trunk".

Once you've finished your work in the branch repository, you need to get ready to merge back into "trunk". This is where the power of DVCS comes in, but it is also a bit different than what you are used to if you are coming from a typical, centralized VCS.

Because you have a complete repository on your machine that shares history with the repository you branched from, you can actually perform the merge on your machine, and record that action in source control. The fact that you have both the state of the files and the changes made during the merge in source control means it is nearly impossible to lose information during the merge. You can always roll back and re-merge if anything goes wrong.

To perform the merge, you'll first want to pull the changes from the "trunk" into your local repository and merge those changes with the changes you've made.

> hg pull https://your.fogbugz.com/kiln/repo/my/kiln/trunk
pulling from https://your.fogbugz.com/kiln/repo/my/kiln/trunk
searching for changes
adding changesets
adding manifests
adding file changes
added 4 changesets with 5 changes to 4 files (+1 heads)
(run 'hg heads' to see heads, 'hg merge' to merge)

> hg merge
4 files updated, 0 files merged, 0 files removed, 0 files unresolved

> hg commit -m "merge"

Once this is done, you will have saved, in your local repository, all of your changes plus all of the changes that have been going on in the "trunk" repository. You can now push your changes to the "trunk" repository and your branch repository without conflict.

> hg push https://your.fogbugz.com/kiln/repo/my/kiln/trunk
pushing to https://your.fogbugz.com/kiln/repo/my/kiln/trunk
searching for changes
kiln: successfully pushed 2 changesets
> hg push
pushing to https://your.fogbugz.com/kiln/repo/my/kiln/branch
searching for changes
kiln: successfully pushed 5 changesets

These pushes will ensure that all of the changes that were in the branch are now included in "trunk" repository on the server and vice versa. You now have the choice to either remove the branch repository, or keep it around if you plan on continuing development there. You must be an administrator to remove a repository, but you get to it through the Settings tab in the repository view:

Delete a repo

link|flag
Does one HAVE to create the branch through the web interface in order for Kiln to pick it up? For example, hg will let you create an anonymous branch repository whenever you would like on your local machine. Is there any way to not have to context switch all the way back to the website to create a branch? Also, hg can also create named branches within a repository, giving you a multi-headed repository. Does how does Kiln deal with this? – cdeszaq Feb 8 2010 at 17:55
You do have to create the branch in the website to get the full benefit from Kiln. For most of the people I've seen use Kiln, they have the web interface open (alongside FogBugz) pretty much all day, so it isn't that expensive. It also isn't something people do all that frequently so the cost doesn't add up very fast. Ultimately, we would like a better way to handle this on the client, but we aren't there yet. Also, Kiln handles named branches just fine, but they don't get any special treatment on the server side or in the web interface. – Jason Rosoff Feb 8 2010 at 20:11
@Jason How do you get the neat torn paper effect on the screen shots? – Matt Feb 21 2010 at 22:57
That's built into SnagIt which I used to take the screen shots. – Jason Rosoff Feb 22 2010 at 3:31
Note that to create a branch through the UI as described here you need to click 'Advanced Options' then select 'Branch Repository'. The default is to create a new 'Central Repository'. – Matthew Murdoch Apr 27 2010 at 13:15
show 6 more comments
5

Rob Conery posted a video showing how to use the TortoiseHG client to branch & merge. It is specifically for CodePlex but it is a good insight into using TortoiseHG.

link|flag
It's important to note that the Kiln notion of branching and the native HG notion of branching are disjoint (completely different) things. Kiln branching is a forest of disconnected partially replicated copies, whereas hg branching is intentional where people who have copies of a repository have copies of all its branches, as a matter of intentional design. In other words, kiln weakens hg branching. – WarrenX1 Dec 15 2011 at 21:20
Good point. Anyone who reads this answer &/or watches the video - have a look around this forum and note that there are 2 distinctly different styles of branching in Kiln. They both work but you'll need to muck with them a bit to see what works for you. I, personally, like named branches. Learn both, then decide. – CADbloke Dec 22 2011 at 3:35
3

Hello,

I think your branching model is nice. However, I have a comment regarding your statement:

It is important to reiterate here that the branch you just created is actually a full-fledged repository. You work with it just like you would any other repository. That starts with cloning. When I am working in a branch, I usually just move my copy of the "trunk" repository out of the way by renaming the folder on my machine (e.g., kiln -> kiln-trunk), and then clone the branch repository to the old trunk location. That way I don't have to change anything in my development environment.

As I understand, on your servers you perform a "hg clone" to hardlink as much as possible (saving disk space). Here, suggesting cloning from the remote server I think is not the best idea. You could just do locally (the user, on his/her computer) a "hg clone foo foo-featureX" modifying .hg/hgrc to point to the branched repo, so disk space is also saved in user's hard disk.

link|flag
One issue with this (that I hope will be resolved soon) is that you have no place to push up to on the server with a local repo clone :( – cdeszaq Jul 28 2010 at 19:12
1 
I believe Rafael meant that you would create the branch repository online normally, but rather than clone it from the web to your local disk (making a full copy), you could clone the existing repository from your disk, and edit the .hg/hgrc file, so that you'd end up with the same thing, but with hard-links to your original repository, rather than total duplicates of the files. – Danny Tuppeny Aug 7 2010 at 20:42
0

As I understand, on your servers you perform a "hg clone" to hardlink as much as possible (saving disk space). Here, suggesting cloning from the remote server I think is not the best idea. You could just do locally (the user, on his/her computer) a "hg clone foo foo-featureX" modifying .hg/hgrc to point to the branched repo, so disk space is also saved in user's hard disk.

Correct, but you can also fix that after the fact using the relink extension (or the hg-relink script in contrib/ for older versions of mercurial).

link|flag
0

To perform the merge, you'll first want to pull the changes from the "trunk" into your local repository and merge those changes with the changes you've made. ...

Once this is done, you will have saved, in your local repository, all of your changes plus all of the changes that have been going on in the "trunk" repository. You can now push your changes to the "trunk" repository and your branch repository without conflict.

What if another user pushes to the trunk in between the time you pull from the trunk and merge locally/push back to the trunk? There will be changes in the trunk that are not in your local repository, opening you up to conflicts (as indicated by the last sentence).

Isn't it better to think of this process as trying to minimize conflicts rather than being able to prevent them outright?

link|flag
0

FYI, to do a TortoiseHG pull from the trunk:

  • From Workbench, File>Settings
  • Select your projects tab, click "Edit File" button near the top
  • Change URL path to "trunk path"
  • Close and reopen workbench
  • Do a normal Pull/merge. You just pulled changes from trunk into branch.
  • Change path settings back to your branch.
  • Close and reopen workbench

Now your back to being pointed at your branch repository on the server.

Obviously the command line is easier, but if you live in Tortoise this might be helpful.

link|flag
0

How to update a branch repository after branching the repository from kiln?......

link|flag
Hi jayachandran! Our customer support team would be happy to help answer your questions. Please email us at customer-service@fogcreek.com so we can discuss further. – Max Kramer Dec 5 at 20:30

Your Answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.