How to Install Git on FreeBSD

October 26, 2022

Introduction

Git is the world's most popular version control system allowing developers to handle projects of all sizes quickly and efficiently. It is available on a wide variety of systems, including FreeBSD.

Git on FreeBSD provides a highly stable, secure, and lightning-fast experience. FreeBSD is best known for its dependability, performance, networking, and storage features, making it a powerful system and a great base for source-code management.

In this tutorial, you will learn to install Git on FreeBSD.

How to install Git on FreeBSD - tutorial.

Prerequisites

  • A system running FreeBSD. In this tutorial, we are using FreeBSD 13.1.
  • A working network connection.
  • A user account with administrator privileges.

How to Install Git on FreeBSD

There are two ways to install Git on FreeBSD:

  • Using packages.
  • Using ports.

Packages and ports scan the system for dependencies and automatically install any missing dependent libraries.

Follow the steps below to install Git on FreeBSD using your method of choice.

Note: Ensure that sudo is installed on FreeBSD before running the commands below. If it isn't installed, the commands throw an error. Install sudo on FreeBSD by running:

pkg update && pkg upgrade
pkg install sudo

Method 1: Install Git on FreeBSD via Packages

The easiest and fastest way to install Git on FreeBSD is using the default package index. Follow the steps below:

Step 1: Update the Package Repository

Before installing Git, ensure the system package repository is up to date:

sudo pkg update -f
Updating the package repository on FreeBSD.

Wait for the update to complete.

Step 2: Install Git

Run the following command to download and install Git:

sudo pkg install git

After installing, the output states which version of Git is installed:

Installing Git on FreeBSD using packages.

Method 2: Install Git on FreeBSD via Ports

Ports are a collection of over 20,000 third-party programs available for free on FreeBSD. Compared to packages, ports offer more customization options but require more time to install Git. The installation process is much slower because the process involves building, i.e., compiling the packages from source code.

Ports are managed using the ports tree, located at /usr/ports, which contains information on each available piece of software for FreeBSD.

Follow the steps below to install Git on FreeBSD using Ports:

1. Download Ports Tree

Download the ports tree to your FreeBSD system. This is done only once, so if you have previously installed packages using ports, you have already downloaded the tree and there is no need to do it again. In that case, skip this step and move on to Step 2.

Download the ports hierarchy tree by running:

sudo portsnap fetch extract

The download completes and new index files are generated:

Download the ports tree in FreeBSD.

Step 2: Update Ports Tree

Update the ports tree by running the following command:

sudo portsnap fetch update

Step 3: Change Directory to Git

Before installing Git, make sure to change the operating directory to the devel/git directory of the ports tree.

cd /usr/ports/devel/git
Changing directory in FreeBSD.

Step 4: Install Git

Build Git from the added sources by running the following command:

sudo make install clean BATCH="yes"

Specifying the BATCH="yes" flag instructs FreeBSD to build the Git port quietly without any prompts. Omit the flag if you want to select which program parts to install. The installation process may take a while, so wait until the system finishes and cleans up all the unnecessary files.

Installing Git on FreeBSD using ports.

When the process finishes installing and cleaning up the files, move on to the next section and configure Git.

How to Configure Git on FreeBSD

The git config command allows you to query, set, replace, or unset values in Git configuration files. By default, the program reads values from the system, global, and local repository configuration files. The most prominent git config command options are:

  • --system. Writes to the system-wide /etc/gitconfig file rather than the repository .git/config file.
  • --global. Writes to the global /.gitconfig file rather than the repository .git/config file.
  • --local. Writes to the repository .git/config file.
  • --worktree. Similar to --local except that $GIT_DIR/config.worktree is read from or written to if extensions.worktreeConfig is enabled.
  • --file [config-file]. Writes settings to the specified file rather than the repository .git/config file.
  • --add. Adds a new line to the configuration file without altering existing values.

The options instruct the command to read values only from the specified location. For a full list of configuration variables, run:

git help config
Git config help file.

Follow the steps below to configure a Git installation on FreeBSD:

1. View Existing Settings

Run the following command to view existing Git settings:

git config --list
Reading the Git configuration file.

The command pulls the settings from the ~/.gitconfig file.

Note: If there is no output, the configuration file is empty. Make sure you have initialized a Git repository and started tracking files for the configuration file to appear.

2. Change Git Username

One of the settings Git allows you to change is the username. To update the username, use:

git config --global user.name "[username]"

For [username], specify the username you want to set. For example:

git config --global user.name "phoenixnap"

The command updates the username to phoenixnap.

3. Change Email Address

Update the default email address using the following syntax:

git config --global user.email "email-address"

For example:

git config --global user.email "[email protected]"

The command updates the email address to [email protected].

4. Change Default Text Editor

The default text editor Git uses is vim. A text editor is necessary when describing changes, adding messages to commits or stashes, creating annotated tags, etc. Specify another text editor using the following syntax:

git config --global core.editor "editor-name"

For example, to change the default text editor to nano, run the following command:

git config --global core.editor "nano"

The command sets the default editor to nano.

Note: Check out our list of the 22 best text editors for coding.

5. Check Changes

Open the Git config file again to check if the updates have been applied:

git config --list
Checking changes in the Git configuration file.

The output shows all the changes we have previously set.

Conclusion

This tutorial showed how to install Git on FreeBSD and configure it.

For more Git tutorials, check out how to install Git on CentOS 8, CentOS 7, Ubuntu, macOS, or Windows. Alternatively, refer to our Git step-by-step beginner's guide and learn how to use Git effectively.

Was this article helpful?
YesNo
Bosko Marijan
Having worked as an educator and content writer, combined with his lifelong passion for all things high-tech, Bosko strives to simplify intricate concepts and make them user-friendly. That has led him to technical writing at PhoenixNAP, where he continues his mission of spreading knowledge.
Next you should read
How to Use git submodule init
September 28, 2022

This tutorial shows how to use git submodule init and provides the most common examples. The command adds submodule entries to the local Git configuration file.
Read more
How to Restore a Git Stash
September 27, 2022

Git stashes allow you to continue working on unfinished code previously set aside. See two different methods for restoring an existing Git stash - using the pop or the apply command.
Read more
Git Tag: An Overview of the Basic Functions
September 6, 2022

This guide shows an overview of basic functions to perform with Git tags. See how to create, delete, push, replace, or checkout a Git tag.
Read more
How to Create a New Branch in Git
January 9, 2024

This article outlines the basic commands needed to create a Git branch. A Git branch allows you to work on features independently.
Read more