Setting Up Git on FreeBSD

In this tutorial, I explain how to set up Git on FreeBSD and show you some useful Git tools.

What is Git

Git is a free and open-source distributed version control system designed to manage everything from small to large projects quickly and efficiently.

We can install Git as follows:

$: doas pkg install git 

For Git to know which user we are, we also run the following commands.

$: git config --global user.email "you@example.com"
$: git config --global user.name "Your Name".

Create SSH Keys

If we have private repositories on GitHub and we want to check them out on our PC, we need an SSH key.

We can easily create an SSH key with the following command:

$: ssh-keygen -t ed25519 -C "your_email@example.com"

Then we can output the newly created public key with the following command:

$: tail ~/.ssh/id_ed25519.pub

We copy the output and can now enter the public key in the user settings in GitHub.

What is Git-Flow

Git-Flow by Vincent Driessen is a branching and version management workflow in Git that helps developers keep track of features, hotfixes, and versions in larger software projects. This workflow involves many commands to type and remember. The git-flow library of git subcommands can help by automating some parts of the workflow to make it easier to work with.

We can install git-flow as follows:

$: doas pkg install gitflow

After installing git-flow, we use the git flow init command to use git-flow in a repository. To create a new repository, run git flow init in an empty directory:

$: git flow init

Initialized empty Git repository in ~/project/.git/
No branches exist yet. Base branches must be created now.
Branch name for production releases: [master]
Branch name for "next release" development: [develop].

How to name your supporting branch prefixes?
Feature branches? [feature/]
Release branches? [release/]
Hotfix branches? [hotfix/]
Support branches? [support/]
Version tag prefix? []

Now we could use the commands from here, but I want to show you a simplification. If you followed my ZSH instructions, we can add the following to our ZSH configuration file:

$: nano ~/.zshrc ⇒

gffs() {
    git flow feature start $1
}

gfff() {
    git flow feature finish $1 && git push
}

gfrs() {
    git flow release start $1
}

gfrf() {
    git flow release finish $1 && git push --tags && git checkout master && git push && git checkout develop && git push
}

gfhs() {
    git flow hotfix start $1
}

gfhf() {
    git flow hotfix finish $1 && git push --tags && git checkout master && git push && git checkout develop && git push
}

Now I'll explain what each command does.

gffs

With gffs we can start a new feature.

Example:

gffs feat/feature_name

gfff

When we have finished developing a feature, we can use the gfff command to end the feature.

gfff feat/feature_name

Now what does it do exactly, we tell Git Flow that we have finished this feature. Then it will be merged into the developer branch and then it will automatically push it into Git.

gfrs

After some time, when we have developed enough features, we can start a new release with the gfrs command.

gfrs v1.0.0

Git-Flow now creates a release branch with the tag v1.0.0. We can now either create the release notes or add other short-term fixes.

gfrf

When we are satisfied with the release branch, we can finalize the release with the gfrf command.

gfrf v1.0.0

Git flow now finalizes the release branch, pushes the release tag with the appropriate release number into git, then pushes everything into the master and develop branch.

gfhs

As with any development, bugs may occur on the master system, where a hotfix then needs to be pushed out. We can then do the whole thing with the gfhs command.

gfhs v1.0.1

With this command, a new branch of Master is created. And we can then prepare the hotfix.

gfhf

After the hotfix is ready. We use the command gfhf.

gfhf v1.0.1

When we run this command, the hotfix will be pushed to master first and also automatically pushed back to the develop branch.

Git Tools

In this section, I would like to introduce useful Git-related programs. They can be very helpful.

git-delta

git-delta is a syntax highlighting pager for git, diff and grep output.

We can install git-delta as follows:

$: doas pkg install git-delta

Next, we can create the following configuration file.

$: nano ~/.gitconfig ⇒

[core]
    pager = delta

[interactive]
    diffFilter = delta --color-only

[delta]
    navigate = true

[merge]
    conflictstyle = diff3

[diff]
    colorMoved = default

git-bug

git-bug is an offline-first bug tracker embedded in Git that:

We can install it as follows:

$: doas pkg install git-bug

First, we change to a git repository directory where we want to use git-bug, then first we have to use the command:

$: git bug user create

command.

Thereafter, we can either use the CLI, the interactive terminal, or the web UI.

If we use the CLI, I recommend you to have a look at the command list here.

We open the interactive terminal UI with

$: git bug termui

or with the command:

$: git bug webui

we can open a web UI based on the React framework and looks like this.

There is also an interface connection to the bug trackers GitHub, GitLab, and Jira. For this, we run the command:

$: git bug bridge configure

and we are interactively guided through the configuration.

Interested to see how git-bug works? Have a look at the data model and the internal architecture.

git-extras

Another helpful GIT package is the git-extras collection. It includes commands such as repo summary, repl, changelog population, percentage of author commits, and more, among others.

We can install git-extras like this:

$: doas pkg install git-extras

Let me show you 2 examples of what the package includes.

We can output the contributions of an author to a project, let's run the following:

$: git contrib visionmedia ⇒ 

visionmedia (18):
  Export STATUS_CODES
  Replaced several Array.prototype.slice.call() calls with Array.prototype.unshift.call()
  Moved help msg to node-repl
  Added multiple arg support for sys.puts(), print(), etc.
  Fix stack output on socket error
  ...

Or we can also print a summary of the repo:

$: git summary ⇒ 

project: git-extras
repo age: 10 months ago
commits: 163
active: 60 days
files: 93
authors :
   97 Tj Holowaychuk 59.5%
   37 Johnny Weslley 22.7%
    8 Kenneth Reitz 4.9%
    5 Aggelos Orfanakos 3.1%
    3 Jonathan "Duke" Leto 1.8%
    2 Gert Van Gool 1.2%
    2 Domenico Rotiroti 1.2%
    2 Devin Withers 1.2%
    2 TJ Holowaychuk 1.2%
    1 Nick Campbell 0.6%
    1 Alex McHale 0.6%
    1 Jason Young 0.6%
    1 Jens K. Mueller 0.6%
    1 Guillermo Rauch 0.6%

More useful commands can be found here.

git-chglog

Next, I would like to introduce you to git-chglog. It is a changelog generator implemented in Go.

It offers the following features:

We can install it as follows

$: doas pkg install git-chglog

In the next step, we can switch to a git repository. And run once the command

$: git-chglog --init

This command will then interactively create a configuration file and a changelog template.

We can now create a changelog file with the following command:

$: git-chglog -o CHANGELOG.md

gitg

gitg is a graphical user interface for Git. It is a small, fast and handy tool to visualize the history of Git repositories. Besides visualization, gitg also provides various utilities to manage our repository and commit our work.

We can easily install it with

$: doas pkg install gitg

Discuss...