Git is one of the most popular distributed version control systems. Many projects maintain their files in a Git repository, and sites like GitHub and Bitbucket have made sharing and contributing to code simple and valuable.
In this article, we'll walk you through the steps to install and configure Git on a FreeBSD 11.0 server. We will demonstrate how to install the software in two different ways, each of which has its own benefits.
To follow this tutorial, you will need:
- One FreeBSD 11 machine with a root user.
Installing Git via Packages
This the first installation method uses the FreeBSD package index. This is generally the easiest and fastest way to install Git.
First, update the pkg repository index.
sudo pkg update -f
Next, download and install the git package.
sudo pkg install git
You'll need to enter y to confirm the installation. That's it!
You can now move on to the Configuring Git section below to see some basic, useful customization options.
Installing Git via Ports
The FreeBSD ports system is another method of manging applications on a FreeBSD server. It's managed through a filesystem hierarchy called the ports tree, located at /usr/ports, which categorizes each available piece of software that FreeBSD knows how to build. portsnap is a tool that comes with FreeBSD and simplifies working with the ports tree.
Install Git via ports will take longer than installing it via packages, as you will be building it and several dependencies from source (rather than downloading precompiled binaries, as you would do with pkg). The benefit of using ports is a higher level of customization.
First, if you haven't already, download and extract the ports tree files into /usr/ports. This may take a while, but you only ever have to do it once.
sudo portsnap fetch extract
If you already have the ports tree downloaded, instead you should update it with:
sudo portsnap fetch update
Then, move to the devel/git directory in the ports tree.
Finally, build Git. Including BATCH="yes" in this command will install the Git port quietly and avoid the many dialogs along the way asking which parts of certain software you would like installed. You can omit this if you would like to be prompted for which components of each port to install; hitting ENTER will assume the default.
sudo make install clean BATCH="yes"
Now that Git is installed, we can configure it.
First, let's view the existing Git configuration settings. These are pulled from the ~/.gitconfig file.
git config --list
From here, you can update any settings you'd like. For example, update your username with the following command replacing jhon with your username.
git config --global user.name "jhon"
You can update your email address with this command, replacing firstname.lastname@example.org with your email address.
git config --global user.email "email@example.com"
Specify your default text editor by replacing vim below with your preferred text editor.
git config --global core.editor "vim"
You can check that your updates went through by looking at your configuration settings again.
git config --list
We have completed Git installation and configuration on FreeBSD 11.0 server.