- Gitahead 1 2 – The Easiest Way To Use Git Delete
- Music App
- Getahead 1 2 – The Easiest Way To Use Git Github
Git, the version control system originally written by Linus Torvalds, is one of the most widely used Linux commands. Like other popular commands, such as apt or vim, an entire ecosystem of tools has grown up around it. In fact, Debian’s stable repository alone lists over 60 secondary tools whose names start with “git” and around 70 with unique names.
These tools cover a vast range of functions. Some, like git-github and git-gitlab, help you more efficiently use other services. Others enable particular text editors: git-el enables Emacs support, while git-email adds functionality. Still others are commands to run reports on authors, commits, and other activities; to generate packages and send them to the repositories of distributions from within Git; to clean up repositories; and much more. There is even Gitless, an experiment to create a version control system on top of Git. Most of these tools are standalone scripts, but a minority are add-ons to Git and run as an option to the basic git command. Look beyond the Debian repositories, and you are likely to find as many choices again.
Option One — Install Git with Yum. The easiest way to install Git and have it ready to use is to use CentOS’s default repositories. This is the fastest method, but the Git version that is installed this way may be older than the newest version available. Understand your Git history! Contribute to gitahead/gitahead development by creating an account on GitHub. Unique sidebar and open tab names in the same way as recent repositories. Added 'Fetch All' item to 'Remote' menu. Fixed failure to launch external edit tools with spaces in their path.
Some users install git-all and sort through all the secondary tools at their leisure. But what if you are more selective about what you put on your hard drive? Below are seven general utilities that can benefit most Git users.
git-big-picture
The command line is text-oriented, but some users benefit from a visual aid. For these users, git-big-picture provides a visualization tool that is the equivalent to git branch. It displays branches in numerical and then alphabetical order. For other users, the command provides a memory aid, perhaps as a map to monitor large numbers of branches. The command structure is:
The formats supported are SVG, PNG, PS, and PDF (Figure 1). By specifying a viewer, you open the result right after the command is processed.
Figure 1: git-big-picture provides a map of the current repository that can be kept open in a separate window.
git-cola
While Git is designed to work from the command line, sometimes you need a graphical interface for an overview. Of all the half dozen or so graphical interfaces for Git, git-cola is by far the most efficient; its developer describes git-cola as a “caffeinated” version of Git.
The git-cola GUI consists of three main windows (Figure 2). The first window is a file manager that lets you choose a Git repository. The second is the main working window, with Status, Commit, Branches, and Diff panes and accompanying menus. This window is likely to be immediately comprehensible to anyone with a basic understanding of Git. The third shows a detailed view of the current branch and its contents, as well as a map of all the repository’s branches. Like the second window, the third has a simple top-level structure, but some of its dialogs demand more expertise and can be formidable in their detail.
Figure 2: git-cola offers an easy-to-navigate graphical interface.
git-crecord
Based on a similar tool for the Mercurial version management system, git-crecord can commit files in batches and set up comparisons in Git. In addition, its graphical interface and color-coding provides an overview of the repository. For example, in Figure 3, three files are staged, but not yet committed. Using git-record, users can choose to commit all three files or only one or two.
Be aware that git-crecord integrates with the git-core, so that its command structure is git crecord. It has no options and therefore no man page.
Figure 3: git-crecord provides a basic interface for batch operations.
git-crypt
This tool provides encryption to be used with a Git repository. It can be used to decide which files should be encrypted and which users can encrypt or decrypt. To set up an encrypted Git repository, use gpg --gen-key to create a key for each user.
Next, to make files visible locally, but not on a pull request (i.e., remotely), run git-crypt init to initialize the repository for use. Then select the files that will be affected by creating a .gitattributes file to place in the repo. For each file to encrypt, use the format:
Wildcards can be used to reduce the number of entries. According to some users, you can ensure that .fileattributes is not encrypted by adding the line:
However, my system reads the line as an error.
The only ways remote users can read the encrypted files is if their encryption key is added using the command
or if the repository key is exported with:
After which, the remote user can access the files with:
You can also temporarily make the files accessible to everyone by using git-crypt unlock. To re-encrypt, use the lock option.
git-repair
The core of Git includes a fsck command. However, while fsck finds problems in a repository, it does not fix them. By contrast, git-repair runs fsck and makes what repairs it can. First, git-repair deletes corrupt objects and retrieves remote versions of missing objects. After that, if the repository is still corrupt, using the --force option, git-repair can revert branches to an uncorrupt state, delete lost branches, and remove missing files from the index. Note that git-repair’s purpose is to create a functional repository, not to recover everything. Consequently, you may need to recover some files from cloned repositories or backups. After running git-repair, you should run git fsck and git gc to finish the restoration (Figure 4).
Gitahead 1 2 – The Easiest Way To Use Git Delete
Figure 4: git-repair works to restore a corrupted repository.
git-sizer
Git repositories are intended for source text. For that reason, they work best when smaller than one gigabyte and can become unwieldy at about five gigabytes. Although it might be convenient to store all Git-related material in the same directory, it is more efficient to have another directory for media files, logs, and files generated by other commands. Periodically, too, you might check for unnecessary branches. This housekeeping is simplified by git-sizer, a simple command without any options, that reports on the contents of a repository and flags any potential problems. As a side effect, git-sizer also provides an overall view of a repository’s contents (Figure 5).
Figure 5: git-sizer gives information to help you control the size of a repository.
Music App
git-extras
For staging and committing files as well as using with diff, git-extras provides a basic graphical interface.
As if 60 utilities in the repositories were not enough, git-extras collect over 80 scripts for Git. While git-extras has its own man page, each script also has a man page. Like the packages in the repository, git-extras covers a wide variety of purposes. Some of these scripts duplicate functions that are already in Git, but with different, improved options. Many make housekeeping tasks for branches easier. Five of the most useful are:
- git-back: Removes the latest commits. The bare command removes the last commit; if followed by a number, it removes that many of the latest commits.
- git-bulk: Runs standard git commands on multiple repositories at the same time. The command could, of course, cause unintentional damage if used carelessly. For this reason, it should be used with the -g option, which asks for approval before making any change.
- git-sed: Searches the files in a repo for a string and replaces it with a string.
- git-merge-repo: Merges two repos.
- git-obliterate: Rewrites commits, changing both contents and histories.
There is not enough space to mention all the goodies in git-extras. Install it and explore for yourself -- it’s a must-have for almost everyone.
Finding More Commands
If git-extras is not enough, there is no shortage of other enhancements, especially if you delve into specialty areas. GitHub alone returns 79 results in a search for “git add-ons.” An especially noteworthy repository is Steve Mao’s Awesome Git Add-Ons, which links to demonstrations of dozens of tools. These sources alone can take hours to explore.
Of course, remembering the optimal size for repositories that is the reason for git-sizer, you will likely want to be cautious about commands that add their command files to a repository itself. After all, the last thing you want is to fill the repository directory with tools rather than your development files. However, if you are willing to take the time, you can soon have your Git repositories running exactly as you want.
Note of reflection (March 5, 2020)
This model was conceived in 2010, now more than 10 years ago, and not verylong after Git itself came into being. In those 10 years, git-flow (thebranching model laid out in this article) has become hugely popular in manya software team to the point where people have started treating it likea standard of sorts — but unfortunately also as a dogma or panacea.
During those 10 years, Git itself has taken the world by a storm, and themost popular type of software that is being developed with Git is shiftingmore towards web apps — at least in my filter bubble. Web apps are typicallycontinuously delivered, not rolled back, and you don't have to supportmultiple versions of the software running in the wild.
This is not the class of software that I had in mind when I wrote the blogpost 10 years ago. If your team is doing continuous delivery of software,I would suggest to adopt a much simpler workflow (like GitHubflow) instead of trying toshoehorn git-flow into your team.
If, however, you are building software that is explicitly versioned, or ifyou need to support multiple versions of your software in the wild, thengit-flow may still be as good of a fit to your team as it has been to peoplein the last 10 years. In that case, please read on.
To conclude, always remember that panaceas don't exist. Consider your owncontext. Don't be hating. Decide for yourself.
In this post I present the development model that I’ve introduced for some ofmy projects (both at work and private) about a year ago, and which has turnedout to be very successful. I’ve been meaning to write about it for a while now,but I’ve never really found the time to do so thoroughly, until now. I won’ttalk about any of the projects’ details, merely about the branching strategyand release management.
Why git? ¶
For a thorough discussion on the pros and cons of Git compared to centralizedsource code control systems, see theweb. There are plenty of flamewars going on there. As a developer, I prefer Git above all other tools aroundtoday. Git really changed the way developers think of merging and branching.From the classic CVS/Subversion world I came from, merging/branching has alwaysbeen considered a bit scary (“beware of merge conflicts, they bite you!”) andsomething you only do every once in a while.
But with Git, these actions are extremely cheap and simple, and they areconsidered one of the core parts of your daily workflow, really. For example,in CVS/Subversion books, branching and mergingis first discussed in the later chapters (for advanced users), while ineveryGitbook, it’s already covered in chapter3 (basics).
As a consequence of its simplicity and repetitive nature, branching and mergingare no longer something to be afraid of. Version control tools are supposed toassist in branching/merging more than anything else.
Enough about the tools, let’s head onto the development model. The model thatI’m going to present here is essentially no more than a set of procedures thatevery team member has to follow in order to come to a managed softwaredevelopment process.
Decentralized but centralized ¶
The repository setup that we use and that works well with this branching model,is that with a central “truth” repo. Note that this repo is only consideredto be the central one (since Git is a DVCS, there is no such thing as a centralrepo at a technical level). We will refer to this repo as
origin
, since thisname is familiar to all Git users.Each developer pulls and pushes to origin. But besides the centralizedpush-pull relationships, each developer may also pull changes from other peersto form sub teams. For example, this might be useful to work together with twoor more developers on a big new feature, before pushing the work in progress to
origin
prematurely. In the figure above, there are subteams of Alice and Bob,Alice and David, and Clair and David.Ilock 3 0 2 x 2. Technically, this means nothing more than that Alice has defined a Git remote,named
bob
, pointing to Bob’s repository, and vice versa.The main branches ¶
At the core, the development model is greatly inspired by existing models outthere. The central repo holds two main branches with an infinite lifetime:
master
develop
The
master
branch at origin
should be familiar to every Git user. Parallelto the master
branch, another branch exists called develop
.We consider
origin/master
to be the main branch where the source code ofHEAD
always reflects a production-ready state.We consider
origin/develop
to be the main branch where the source code ofHEAD
always reflects a state with the latest delivered development changesfor the next release. Some would call this the “integration branch”. This iswhere any automatic nightly builds are built from.When the source code in the
develop
branch reaches a stable point and isready to be released, all of the changes should be merged back into master
somehow and then tagged with a release number. How this is done in detail willbe discussed further on.![The The](https://d2.alternativeto.net/dist/s/gitahead_563476_full.png?format=jpg&width=1200&height=1200&mode=crop)
Therefore, each time when changes are merged back into
master
, this is a newproduction release by definition. We tend to be very strict at this, so thattheoretically, we could use a Git hook script to automatically build androll-out our software to our production servers everytime there was a commit onmaster
.Supporting branches ¶
Next to the main branches
master
and develop
, our development model usesa variety of supporting branches to aid parallel development between teammembers, ease tracking of features, prepare for production releases and toassist in quickly fixing live production problems. Unlike the main branches,these branches always have a limited life time, since they will be removedeventually.The different types of branches we may use are:
- Feature branches
- Release branches
- Hotfix branches
Each of these branches have a specific purpose and are bound to strict rules asto which branches may be their originating branch and which branches must betheir merge targets. We will walk through them in a minute.
By no means are these branches “special” from a technical perspective. Thebranch types are categorized by how we use them. They are of course plain oldGit branches.
Feature branches ¶
- May branch off from:
develop
- Must merge back into:
develop
- Branch naming convention:
- anything except
master
,develop
,release-*
, orhotfix-*
Feature branches (or sometimes called topic branches) are used to develop newfeatures for the upcoming or a distant future release. When startingdevelopment of a feature, the target release in which this feature will beincorporated may well be unknown at that point. The essence of a feature branchis that it exists as long as the feature is in development, but will eventuallybe merged back into
develop
Bartender 3 0 57 mph. (to definitely add the new feature to theupcoming release) or discarded (in case of a disappointing experiment).Feature branches typically exist in developer repos only, not in
origin
.Creating a feature branch ¶
When starting work on a new feature, branch off from the
develop
branch.Incorporating a finished feature on develop ¶
Finished features may be merged into the
develop
branch to definitely addthem to the upcoming release:The
--no-ff
flag causes the merge to always create a new commit object, evenif the merge could be performed with a fast-forward. This avoids losinginformation about the historical existence of a feature branch and groupstogether all commits that together added the feature. Compare:In the latter case, it is impossible to see from the Git history which of thecommit objects together have implemented a feature—you would have to manuallyread all the log messages. Reverting a whole feature (i.e. a group of commits),is a true headache in the latter situation, whereas it is easily done if the
--no-ff
flag was used.Yes, it will create a few more (empty) commit objects, but the gain is muchbigger than the cost.
Release branches ¶
- May branch off from:
develop
- Must merge back into:
develop
andmaster
- Branch naming convention:
release-*
Release branches support preparation of a new production release. They allowfor last-minute dotting of i’s and crossing t’s. Furthermore, they allow forminor bug fixes and preparing meta-data for a release (version number, builddates, etc.). By doing all of this work on a release branch, the
develop
branch is cleared to receive features for the next big release.The key moment to branch off a new release branch from
develop
is whendevelop (almost) reflects the desired state of the new release. At least allfeatures that are targeted for the release-to-be-built must be merged in todevelop
at this point in time. All features targeted at future releases maynot—they must wait until after the release branch is branched off.It is exactly at the start of a release branch that the upcoming release getsassigned a version number—not any earlier. Up until that moment, the
develop
branch reflected changes for the “next release”, but it is unclear whether that“next release” will eventually become 0.3 or 1.0, until the release branch isstarted. That decision is made on the start of the release branch and iscarried out by the project’s rules on version number bumping.Creating a release branch ¶
Release branches are created from the
develop
branch. For example, sayversion 1.1.5 is the current production release and we have a big releasecoming up. The state of develop
is ready for the “next release” and we havedecided that this will become version 1.2 (rather than 1.1.6 or 2.0). So webranch off and give the release branch a name reflecting the new versionnumber:After creating a new branch and switching to it, we bump the version number.Here,
bump-version.sh
is a fictional shell script that changes some files inthe working copy to reflect the new version. (This can of course be a manualchange—the point being that some files change.) Then, the bumped versionnumber is committed.This new branch may exist there for a while, until the release may be rolledout definitely. During that time, bug fixes may be applied in this branch(rather than on the
develop
branch). Adding large new features here isstrictly prohibited. They must be merged into develop
, and therefore, waitfor the next big release.Finishing a release branch ¶
When the state of the release branch is ready to become a real release, someactions need to be carried out. First, the release branch is merged into
master
(since every commit on master
is a new release by definition,remember). Next, that commit on master
must be tagged for easy futurereference to this historical version. Finally, the changes made on the releasebranch need to be merged back into develop
, so that future releases alsocontain these bug fixes.The first two steps in Git:
The release is now done, and tagged for future reference.
Edit: You might as well want to use the
-s
or -u <key>
flags to signyour tag cryptographically.To keep the changes made in the release branch, we need to merge those backinto
develop
, though. In Git:This step may well lead to a merge conflict (probably even, since we havechanged the version number). If so, fix it and commit.
Now we are really done and the release branch may be removed, since we don’tneed it anymore:
Hotfix branches ¶
- May branch off from:
master
- Must merge back into:
develop
andmaster
- Branch naming convention:
hotfix-*
Getahead 1 2 – The Easiest Way To Use Git Github
Hotfix branches are very much like release branches in that they are also meantto prepare for a new production release, albeit unplanned. They arise from thenecessity to act immediately upon an undesired state of a live productionversion. When a critical bug in a production version must be resolvedimmediately, a hotfix branch may be branched off from the corresponding tag onthe master branch that marks the production version.
The essence is that work of team members (on the
develop
branch) cancontinue, while another person is preparing a quick production fix.Creating the hotfix branch ¶
Hotfix branches are created from the
master
branch. For example, say version1.2 is the current production release running live and causing troubles due toa severe bug. But changes on develop
are yet unstable. We may then branch offa hotfix branch and start fixing the problem:Don’t forget to bump the version number after branching off!
Then, fix the bug and commit the fix in one or more separate commits.
Finishing a hotfix branch ¶
When finished, the bugfix needs to be merged back into
master
, but also needsto be merged back into develop
, in order to safeguard that the bugfix isincluded in the next release as well. This is completely similar to how releasebranches are finished.First, update
master
and tag the release.Edit: You might as well want to use the
-s
or -u <key>
flags to signyour tag cryptographically.Next, include the bugfix in
develop
, too:The one exception to the rule here is that, when a release branch currentlyexists, the hotfix changes need to be merged into that release branch, insteadof
develop
. Back-merging the bugfix into the release branch will eventuallyresult in the bugfix being merged into develop
too, when the release branchis finished. (If work in develop
immediately requires this bugfix and cannotwait for the release branch to be finished, you may safely merge the bugfixinto develop
now already as well.)Finally, remove the temporary branch:
Summary ¶
While there is nothing really shocking new to this branching model, the “bigpicture” figure that this post began with has turned out to be tremendouslyuseful in our projects. It forms an elegant mental model that is easy tocomprehend and allows team members to develop a shared understanding of thebranching and releasing processes.
A high-quality PDF version of the figure is provided here. Go ahead and hang iton the wall for quick reference at any time.
Update: And for anyone who requested it: here’s thegitflow-model.src.key of the main diagram image (Apple Keynote).
Git-branching-model.pdf