Git Source Control Management

Updated by Phil Zona

Contribute on GitHub

View Project | View File | Edit File

Git is version control software, which is used to keep track of changes to a file or group of files. Version control is usually associated with source code, but can be used on any file type. For example, a technical document may be placed in version control in order to keep track of changes made to the document. Version control can also be applied to graphics. You can rollback to a previous version to keep track of the changes made on a particular file.

This document will provide rudimentary installation instructions as well as some basics for getting started. However, the way you use Git is entirely up to you.

Installing Git

Git can be installed on a variety of operating systems. It can also be downloaded and compiled. However, it is recommended that you use your Linux distribution’s repository installer as this is usually the most reliable installation method.

The steps in this guide are written using a non-root user. If you are logged in as root you will not need sudo for certain steps.

Linux Installation

For Debian and Ubuntu systems, the command is as follows:

sudo apt-get install git

For a CentOS system, the command is as follows:

sudo yum install git

For a Fedora system, the command is as follows:

sudo yum install git-core

For an Arch Linux system, the command is as follows:

sudo pacman -Sy git 

For a Gentoo system, the command is as follows:

sudo emerge ask --verbose dev-util/git

Local System Installation

Git may also be installed on a local machine. The installation procedure for both Mac OS X and Windows operating systems is outlined below.

Mac OS X

There are different ways to install Git on OS X. This may be achieved by installing Homebrew or MacPorts before Git or by downloading the Git installer package. Regardless of the method you choose, make sure you verify which operating system version you are currently running.

Installing Git via Homebrew
  1. Go to the Homebrew website.
  2. Copy and paste the command on that page, under Install Homebrew into a terminal window.

    Enter the install command.

  3. At the next prompt enter your password and hit Return.

    Enter your password.

  4. You will receive an installation successful message when complete.

    Enter your password.

  5. It is recommended that you install Brew Doctor to fix any errors before installing Git, using the command brew doctor. If any errors appear, they will be fixed, and you will see a message stating what was repaired.

    Install brew doctor.

  6. To update Homebrew, enter the following command:

    brew update

    Update Homebrew.

  7. To install Git with Homebrew, enter the following command:

    brew install git
Installing Git via MacPorts
  1. Go to MacPorts website.
  2. Click on the link for your operating system.
  3. Click on the file after it downloads to start the installer.
  4. Click on the Continue button to begin the install.

    Begin MacPort install.

  5. Click on the Agree button to accept the license agreement.

    Agree to the license agreement.

  6. To leave the default installation location click on the Install button or click the Change Install Location button to change the default location.

    Change default location.

  7. Enter your password when prompted and click on the Install Software button.

    Enter your password.

  8. After the install finishes, click the Close button to exit the installer.

    Click close to exit.

  9. Open a terminal window.
  10. To install Git use the following command:

    $ sudo port install git +svn +doc +bash_completion +gitweb
Installing Git via Package Installer
  1. Go to the Git website and download the current installer for your operating system.
  2. Double click on the downloaded file to begin the install.
  3. Click on the Continue button to begin the install.

    Click on continue.

  4. Select Install for all users of this computer button and click Continue to begin the installation.

    Click on install for all users of this computer.

  5. Click Install to continue with the default location. If you need to change the installation location click Change Install Location button.

    Click on change install location.

  6. Enter your username and password and click Install Software to continue.

    Enter username and password and click install software.

  7. Click the Close button to exit the installer.

    Click close to exit.


To install Git on Windows you will need to download the installer from the Git website:

  1. Download the most current version for your operating system by double clicking on the package name.

    Click to download version for Windows.

  2. Select Run to begin the installation.

    Click Run to start the installer.

  3. Click Yes to continue.

    Click Yes to continue.

  4. Click Next to continue.

    Click Next to continue.

  5. Click Next to continue.

    Click Next to continue.

  6. To accept the default location click on Next. If you need to change the installation folder, click on the Browse button and select a new location.

    Click Next for default or Browse to change.

  7. To accept the default components to be installed click Next. Otherwise, select the additional components to be installed before clicking the Next button.

    Accept the default or select additional components.

  8. Accept the default start menu folder by clicking Next or use Browse to select a new folder location.

    Select the start menu folder.

  9. Keep the default line ending conversion by clicking Next. To change the default, choose one of the two other choices before clicking Next.

    Select line ending conversions.

  10. The program will now begin installing.

    Git is installing.

  11. Click Finish to exit the installer.

    Click Finish to exit.

    It is strongly recommended that you keep the default settings for line ending conversions. Changing from the default may result in formatting problems when viewed on your Linode.

  12. Once you open Git you can select either Create New, Clone Existing or Open Existing Repository. In this example, create new repository was selected.

    Create New Repository.

  13. Enter a directory name or click on Browse to navigate to a directory.

    Directory for a new repository.

  14. A blank repository has been created.

    Blank repository.

Configuring Git

After the installation is complete, you will need to configure Git for first time use. There is a built-in tool called git config that obtains and sets configuration variables for how Git functions and appears. These configuration variables are located in three different places on a Linux system:

  • /etc/gitconfig file - stores the information for all system users and their respective repositories
  • ~/.gitconfig file - pertains to your user
  • .git/config - this is the configuration file of your current working repository.

For a Windows system, the .gitconfig file is located in the $HOME directory of the user’s profile. The full path is C:\Document and Settings\$USER or C:\Users\$USER

After installing Git make sure your username and email address are set correctly. To verify, use the command:

git config --list

If your name and email are not listed in the output, you may set them manually. Use the following command to set your name, replacing name with your name:

git config --global name

Use the following command to set your email address, replacing

git config --global

Set your default text editor with this command, replacing editor-name:

git config --global core.editor editor-name

Your output should show the information you entered. Sample output is below:

MacBook-Pro:~ user$ git config --list

Working with the Repository

There are two ways to obtain a Git repository, either by importing or copying. If you have an existing project and you want to start using Git to keep track of its changes, you will need to run the command from the existing project’s directory:

git init

This will create a new subdirectory called .git. In order to start tracking changes made to this project, first add files to be tracked using the following command, replacing filename:

git add filename

After adding the files you wish to track, use the command:

git commit

Enter the commit message using your favorite text editor, then save and quit to finish writing the commit. Alternatively, you can use git commit -m "commit_message" and hit enter, substituting your intended commit message for commit_message.

To copy an existing Git repository use the command:

git clone

Remember that every file will be copied when the git clone command is used. When using a URL, use the following command, replacing url with the URL you wish to clone from:

git clone url

To check the status of the files within your repository use the command:

git status

The status command will also display the status of your submodules. When this command is run it will tell you what branch you are on, and if any tracked files have been modified.

Setup a Local Empty Repository

A newly created repository contains only the .git folder. For this example, we will use a repository named practice. Keep the naming convention simple e.g. lowercase, short names, etc. To create a new repository use the command:

git init practice.git

If you already have a repository on your local machine and want to push it to your new Git server, replace and use the command:

git remote set-url origin git@

Now you should be able to push and pull files from your local PC to your Linode.

Basic File Commands

The most basic commands you will need to know to start using Git are in the table below:

Command Description Example
git add adds a file to a repository git add filename
git rm removes a file from a repository git rm filename
git mv moves or renames a tracked file, directory, or symlink git mv file_from file_to
git branch lists all the local and remote branches git branch branchname
git commit commits all staged objects git commit -m "updates"
git pull downloads all changes from the remote repo and merges them in a specified repo file git pull repo refspec
git push publishes the changes to the remote repo git push repo
git log creates a log of all commits, includes: person, commit, date, time, and msg N/A
gitk displays a visual commit history in a graphical tool N/A
git commit --amend replaces the latest commit in the current branch with a new commit, rewriting history N/A

When using the git pull command, refspec is used to configure which remote branch or branches should be used, and how the local branch or branches should be named. The syntax for refspec is:

git pull name source-branch:destination-branch

Remember to replace name, source-branch, and destination-branch with their respective values.


Branches are made up of individual code changes. For example, by default the main branch is called “master”. The core idea is that branches are created for each feature, implementation, or bug fix. So to use a simplified example, the first or master branch is the trunk of the tree and each branch is a new iteration. In this example, there might be branches broken out by new feature names or specific bug fixes. Git can also be used to track document changes, as well as code.

The basic options used with the git branch command are listed below:

Option Description
-r lists the remote branches
-a shows both local and remote branches
-m renames an old branch
-d deletes a branch
-r -d deletes a remote branch

Working with Remote Repositories

Remote repositories are hosted on a network or another location on the Internet. You can have several remote repositories. This section will provide some basics for working with remote repositories.

To view which remote servers are configured, use the command:

git remote

This will display the short names of your remote repositories. If your repository was cloned, you will see a repository called origin. The default name origin comes from the cloned repository. To view more information about the remote repositories, use the command:

git remote -v

Below are some basic commands for working with remote repositories:

Command Description
git remote add [remote-name] [url] adds a new remote repository
git fetch [repository [refspec]] gathers all the data from a remote project that you do not have yet
git pull obtains and merges a remote branch into your current branch
git push [remote-name] [branch-name] moves your data from your branch to your server
git remote show [remote-name] displays information about the remote you specified
git remote rename [old-name] [new-name] renames a remote
git remote rm [name] removes the remote you specified

Installing Gitolite

  1. Gitolite works on top of Git, and allows access to remote users without having to give them shell access. Install Gitolite with the command:

    sudo apt-get install gitolite
  2. A Linux user needs to be created in order for Gitolite to manage its configuration. This Gitolite user works through Git so do not set a password. The command to create the git user is as follows:

    sudo adduser --system --group --disabled-password git

Create SSH Keys

  1. If you have not already created SSH keys, you will need to do this now. The keys must be created on your local machine. In a terminal window enter the command:

    ssh-keygen -t rsa
  2. Accept the defaults and do not enter a password. The public key will need to be copied up to your Git server. Replace username,, location, and key-name, then use the command:

    scp ~/.ssh/ username@ key-name

The location is where you copied your key. For example:

scp ~/.ssh/ git@

The private key remains on your local system and should not be copied anywhere else.

For Windows users consult the Windows Operating System section in our Public Key guide.

Configure Gitolite

  1. Log in to your Git server with your normal user account. Replace key-location and enter the command:

    gl-setup key-location
  2. Depending on your distribution you may see a warning about the gitolite.rc file. Press enter to continue.

    Enable SSH key.

  3. You will be prompted to enter a number to select a text editor. In this example option 2 was selected, which corresponds with Nano.

    Select a text editor.

  4. The gitolite.rc file will now open in your preferred text editor. The default settings should be used, so exit the file to continue.

    Viewing the gitolite.rc file.

Adding Users


Before users may be added to any of your projects, you will need to clone the Gitolite information from your server to your local machine. Replace both example-user and and enter the following command on your Git server:

git clone example-user@

This will create a new directory called gitolite-admin. Navigate to the newly created directory; if you run ls you will see two files inside conf and keydir. The keydir is the directory where the user keys are stored.

How to Add Users

In order to add a new user, you will need their name, email, and public key. For this example, the name example-user will be used. Replace each instance of example-user with your user name. The procedure is as follows:

  1. Copy the user’s public key:

    cp /path/example-user/public/ ~/gitolite-admin/keydir/
  2. Configure the user’s name:

    git config --global example-user
  3. Configure the user’s email:

    git config --global
  4. Configure the text editor:

    git config --global core-editor editor-name
  5. Now add the user’s public key:

    git add keydir/
  6. Commit the change:

    git commit -a -m "New user example-user added"
  7. Finally push the changes up to the server:

    git push

More Information

You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.

This guide is published under a CC BY-ND 4.0 license.