What can you do with branches?

Being able to create branches easily is great, but that in itself is not the greatest benefit. The real power lies in what you can do with multiple branches, how branches can interact with each other, and most importantly, how you can combine them to bring all the work done in the various branches into the main line of development of the project.

Creating branches

You can create a new branch based on any revision of an existing branch, often the latest revision. The new branch inherits the revision history up until the selected revision. The new branch is completely independent of the original branch; you can commit new revisions in it and create further branches based on it:

Creating branches

Comparing branches

Just like you can compare any two revisions within the same branch, you can also compare any two revisions across any two branches.

For a higher level of comparison (without the detailed differences), it can sometimes be useful to list the revisions (along with their basic information) that exist only in one branch but not in the other.

Merging branches

You can merge one or more branches into another branch. As a result, the merged revisions become part of the target branch, with their historical ordering correctly preserved as they were committed in their original branches:

Merging branches

Mirroring branches

It is often useful to create mirror branches that are exact replicas of the original branch. Mirroring is used extensively to replicate local branches at another location, in order to make them accessible by other team members, or as a way of creating backups.

Mirroring can work in two directions—a push operation creates, converts, or updates another branch to be a mirror of the current branch, while a pull operation converts or updates the current branch to be a mirror of another branch. Both operations copy missing revisions and update the history of the target branch to be identical to the source branch.

Mirroring works only between branches that have not diverged. It is only meaningful when the source branch has all the revisions of the target branch. In our example, the second branch can pull from the first branch, or the first branch can push to the second branch, and the result will be the same:

Mirroring branches
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.189.186.109