This page shows the source for this entry, with WebCore formatting language tags and attributes highlighted.

Title

Encodo Git Handbook 3.0

Description

Encodo first published a Git Handbook for employees in September 2011 and last updated it in July of 2012. Since then, we've continued to use Git, refining our practices and tools. Although a lot of the content is still relevant, some parts are quite outdated and the overall organization suffered through several subsequent, unpublished updates. What did we change from the version 2.0? <ul> We <b>removed</b> all references to the <b>Encodo Git Shell</b>. This shell was a custom environment based on <i>Cygwin</i>. It configured the SSH agent, set up environment variables and so on. Since tools for Windows have improved considerably, we no longer need this custom tool. Instead, we've moved to <i>PowerShell</i> and <i>PoshGit</i> to handle all of our Git command-line needs. We <b>removed</b> all references to <b>Enigma</b>. This was a Windows desktop application developed by Encodo to provide an overview, eager-fetching and batch tasks for multiple Git repositories. We stopped development on this when <i>SmartGit</i> included all of the same functionality in versions 5 and 6. We <b>removed</b> all detailed documentation for Git <b>submodules</b>. Encodo stopped using submodules (except for one legacy project) several years ago. We used to use submodules to manage external binary dependencies but have long since moved to NuGet instead. We <b>reorganized</b> the <b>chapters</b> to lead off with a quick overview of <i>Basic Concepts</i> followed by a focus on <i>Best Practices</i> and our recommended <i>Development Process</i>. We also reorganized the Git-command documentation to use a more logical order. </ul> You can download <a href="{att_link}/encodo_git_handbook_3.pdf">version 3 of the Git Handbook</a> or <a href="{www-en}/documents.php#git-handbook">get the latest copy from here</a>. Chapter 3, <i>Basic Concepts</i> and chapter 4, <i>Best Practices</i> have been included in their entirety below. <h>3 Best Practices</h> <h level="3">3.1 Focused Commits</h> Focused commits are required; small commits are highly recommended. Keeping the number of changes per commit tightly focused on a single task helps in many cases. <ul> They are easier to resolve when merge conflicts occur They can be more easily merged/rebased by Git If a commit addresses only one issue, it is easier for a reviewer or reader to decide whether it should be examined. </ul> For example, if you are working on a bug fix and discover that you need to refactor a file as well, or clean up the documentation or formatting, you should finish the bug fix first, commit it and then reformat, document or refactor in a separate commit. Even if you have made a lot of changes all at once, you can still separate changes into multiple commits to keep those commits focused. Git even allows you to split changes from a single file over multiple commits (the <i>Git Gui</i> provides this functionality as does the index editor in <i>SmartGit</i>). <h level="3">3.2 Snapshots</h> Use the staging area to make quick snapshots without committing changes but still being able to compare them against more recent changes. For example, suppose you want to refactor the implementation of a class. <ul> Make some changes and run the tests; if everything’s ok, stage those changes Make more changes; now you can diff these new changes not only against the version in the repository but also against the version in the index (that you staged). If the new version is broken, you can revert to the staged version or at least more easily figure out where you went wrong (because there are fewer changes to examine than if you had to diff against the original) If the new version is ok, you can stage it and continue working </ul> <h level="3">3.3 Developing New Code</h> Where you develop new code depends entirely on the project release plan. <ul> Code for releases should be committed to the release branch (if there is one) or to the develop branch if there is no release branch for that release If the new code is a larger feature, then use a feature branch. If you are developing a feature in a <i>hotfix</i> or <i>release</i> branch, you can use the optional <b>base</b> parameter to base the feature on that branch instead of the <i>develop</i> branch, which is the default. </ul> <h level="3">3.4 Merging vs. Rebasing</h> Follow these rules for which command to use to combine two branches: <ul> If both branches have already been pushed, then <b>merge</b>. There is no way around this, as you won’t be able to push a non-merged result back to the origin. If you work with branches that are part of the standard branching model (e.g. release, feature, etc.), then <b>merge</b>. If both you and someone else made changes to the same branch (e.g. develop), then <b>rebase</b>. This will be the default behavior during development </ul> <h>4 Development Process</h> A <i>branching model</i> is required in order to successfully manage a non-trivial project. Whereas a trivial project generally has a single branch and few or no tags, a non-trivial project has a stable release—with tags and possible hotfix branches—as well as a development branch—with possible feature branches. A common branching model in the Git world is called <i>Git Flow</i>. Previous versions of this manual included more specific instructions for using the <i>Git Flow</i>-plugin for Git but experience has shown that a less complex branching model is sufficient and that using standard Git commands is more transparent. However, since <i>Git Flow</i> is a very widely used branching model, retaining the naming conventions helps new developers more easily understand how a repository is organized. <h level="3">4.1 Branch Types</h> The following list shows the branch types as well as the naming convention for each type: <ul> <b>master</b> is the main development branch. All other branches should be merged back to this branch (unless the work is to be discarded). Developers may apply commits and create tags directly on this branch. <b>feature/name</b> is a feature branch. Feature branches are for changes that require multiple commits or coordination between multiple developers. When the feature is completed and stable, it is merged to the <i>master</i> branch after which it should be removed. Multiple simultaneous feature branches are allowed. <b>release/vX.X.X</b> is a release branch. Although a project can be released (and tagged) directly from the master branch, some projects require a longer stabilization and testing phase before a release is ready. Using a release branch allows development on the develop branch to continue normally without affecting the release candidate. Multiple simultaneous release branches are strongly discouraged. <b>hotfix/vX.X.X</b> is a hotfix branch. Hotfix branches are always created from the release tag for the version in which the hotfix is required. These branches are generally very short-lived. If a hotfix is needed in a feature or release branch, it can be merged there as well (see the optional arrow in the following diagram). </ul> The main difference from the <i>Git Flow</i> branching model is that there is no explicit stable branch. Instead, the last version tag serves the purpose just as well and is less work to maintain. For more information on where to develop code, see “3.3 – Developing New Code”. <h level="3">4.2 Example</h> To get a better picture of how these branches are created and merged, the following diagram depicts many of the situations outlined above. The diagram tells the following story: <ul> Development began on the master branch v1.0 was released directly from the master branch Development on feature “B” began A bug was discovered in v1.0 and the v1.0.1 hotfix branch was created to address it Development on feature “A” began The bug was fixed, v1.0.1 was released and the fix was merged back to the master branch Development continued on master as well as features “A” and “B” Changes from master were merged to feature “A” (optional merge) Release branch v1.1 was created Development on feature “A” completed and was merged to the master branch v1.1 was released (without feature “A”), tagged and merged back to the master branch Changes from master were merged to feature “B” (optional merge) Development continued on both the master branch and feature “B” v1.2 was released (with feature “A”) directly from the master branch </ul> <img src="{att_link}branching_model.png" href="{att_link}branching_model.png" align="none" caption="Branching Model Example" scale="50%"> Legend: <ul> Circles depict <i>commits</i> Blue balloons are the first commit in a <i>branch</i> Grey balloons are a <i>tag</i> Solid arrows are a <i>required</i> merge Dashed arrows are an <i>optional</i> merge </ul>