Build your own Git server on CentOS 7 and take full control of your code! Learn how to set it up step by step—securely and efficiently. Don’t risk relying on third-party platforms—join the pros who host locally and never look back!
#centlinux #linux #git
Table of Contents
What is Git?
git is a famous version control system. git is used to track changes in computer files and to coordinate work on those files among multiple people. git is primarily used for source-code management by software development teams, however, it can be used to keep track of changes in any set of files. git is freeware and open source. It is packaged with almost every distribution of Linux operating systems.
Git is a distributed version control system designed to handle everything from small to very large projects with speed and efficiency. It tracks changes in source code during software development and is widely used for version control in programming and collaborative projects.

Here’s a detailed overview of Git and its features:
Key Features of Git
- Distributed Version Control:
- Local Repositories: Each developer has a complete copy of the project history on their local machine.
- Collaboration: Developers can work offline, commit changes, and synchronize with others when they are back online.
- Branching and Merging:
- Branch Creation: Create branches to work on new features or fixes without affecting the main codebase.
- Merging: Combine changes from different branches into the main branch.
- Data Integrity:
- SHA-1 Hashing: Git uses SHA-1 hashing to ensure the integrity of the data. Every commit is identified by a unique hash, which helps in detecting changes and potential data corruption.
- Commit History:
- Version History: Git maintains a detailed history of changes, allowing users to review, revert, or roll back changes.
- Efficient Performance:
- Speed: Git is designed for high performance, handling large projects and repositories efficiently.
- Performance: Common operations like committing changes, creating branches, and merging are fast.
- Staging Area:
- Indexing: Changes can be staged before committing, allowing users to review and organize changes.
- Collaboration Workflows:
- Pull Requests/Merge Requests: Tools and services like GitHub, GitLab, and Bitbucket offer additional features for code reviews and pull requests.
- Support for Multiple Workflows:
- Centralized Workflow: A single central repository with multiple contributors.
- Feature Branch Workflow: Creating separate branches for new features.
- Git Flow Workflow: A standardized branching model for managing releases and hotfixes.
Common Git Commands
Command | Description |
---|---|
git init | Initialize a new Git repository. |
git clone [url] | Clone a remote repository to your local machine. |
git add [file] | Stage changes for the next commit. |
git commit -m "message" | Commit staged changes with a message. |
git status | Show the status of working directory and staging area. |
git log | Display commit history. |
git branch | List, create, or delete branches. |
git checkout [branch] | Switch branches or restore working directory files. |
git merge [branch] | Merge changes from one branch into another. |
git pull | Fetch and integrate changes from a remote repository. |
git push | Upload local repository content to a remote repository. |
git fetch | Download changes from a remote repository but do not merge. |
git diff | Show changes between commits, branches, or working directory. |
git reset | Reset the current HEAD to a specified state. |
How Git Works
- Repository Structure:
- Working Directory: Where you make changes to your files.
- Staging Area (Index): A place to prepare changes before committing.
- Local Repository: Stores committed changes and history.
- Remote Repository: A version of the repository on a server used for collaboration.
- Basic Workflow:
- Make Changes: Edit files in the working directory.
- Stage Changes: Add changes to the staging area.
- Commit Changes: Save changes to the local repository.
- Push Changes: Upload changes to a remote repository.
- Pull Changes: Fetch and merge changes from a remote repository.
Recommended Training: The Git & Github Bootcamp from Colt Steele

Benefits of Using Git
- Collaboration: Facilitates team collaboration with features for branching, merging, and pull requests.
- Flexibility: Supports various workflows and branching strategies.
- Control: Offers tools for code review, version tracking, and change management.
- Security: Ensures data integrity and provides a detailed history of changes.
Git vs. Other Version Control Systems
Feature | Git | SVN (Subversion) | Mercurial |
---|---|---|---|
Version Control | Distributed | Centralized | Distributed |
Branching | Lightweight and fast | More cumbersome and slower | Lightweight and fast |
History Management | Full history locally available | History is centralized | Full history locally available |
Performance | High performance for both large and small projects | Performance can vary, especially with large projects | High performance, similar to Git |
Summary
Git is a powerful and flexible version control system that supports both individual and collaborative development workflows. Its distributed nature, combined with features like branching, merging, and staging, makes it an essential tool for modern software development.
Apple 2025 MacBook Air 15-inch Laptop with M4 chip: Built for Apple Intelligence, 15.3-inch Liquid Retina Display, 16GB Unified Memory, 256GB SSD Storage, 12MP Center Stage Camera, Touch ID; Midnight
$1,049.00 (as of June 5, 2025 18:18 GMT +00:00 – More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)Linux Server Specification
In this article, we will setup local git server, then we will create our first git repository for our project, and finally access it from a remote client.
We have two virtual machines, one as the git server, and the other as the git client. Their specifications are:
Hostname: | git-server.itlab.com | git-client.itlab.com |
IP Address: | 192.168.116.129/24 | 192.168.116.128/24 |
Operating System: | RHEL 7.6 | RHEL 7.6 |
Read Also: How to install Git on Rocky Linux 9
Setup Local Git Server on CentOS 7
git rpm is provided in RHEL/CentOS ISO, therefore we can easily install git from a local yum repository.
Connect to git-server.itlab.com using ssh, and install git by using yum command.
yum install -y git
We need a user to own our git repository. Therefore, we add git user and set the password as follows:
useradd git
passwd git
Output:
Changing password for user git.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
Create Your First git Repository
Now, login with git user.
su - git
Execute following commands to create a local git repository.
mkdir ~/repo
cd ~/repo
git init --bare --shared project1
Output:
Initialized empty shared Git repository in /home/git/repo/project1/
Here, we have created a directory repo to keep all of our projects’ repositories in a single place. Then, we have created a bare repository for our project1 project.
Note: A bare repository has no working area, therefore, it is not possible to add files to it locally. While a shared repository is used to allow project members to push changes to the git server.
Enable post-update hook by copying the sample file as follows:
cd ~/repo/project1/hooks/
cp post-update.sample post-update
git access remote repositories via ssh service, therefore, no explicit Linux firewall configuration is required.
Our git server has been successfully configured and we have created an empty repository for our first git project.
Configure a git Client on CentOS 7
Connect to git-client.itlab.com using ssh with root user.
Configure name resolution by adding following line in /etc/hosts.
echo "192.168.116.129 git-server.itlab.com git-server" >> /etc/hosts
Install git rpm by using yum command.
yum install -y git
git is already installed on git-client.itlab.com, therefore, yum didn’t perform any installation.
Connect as ahmer user and configure keybased-authentication between ahmer@git-client.itlab.com and git@git-server.itlab.com.
ssh-keygen
Output:
Generating public/private rsa key pair.
Enter file in which to save the key (/home/ahmer/.ssh/id_rsa):
Created directory '/home/ahmer/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/ahmer/.ssh/id_rsa.
Your public key has been saved in /home/ahmer/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:qJKo3QumkS/Rz/LOqR3gCEOdYH9lLaeGgS1B/QkqrkE ahmer@git-client.itlab.com
The key's randomart image is:
+---[RSA 2048]----+
| o.o= o. |
|. +o.=o. o |
| . +o.= = |
|.E ... * |
|=.o o S |
|+B.o . |
|*o*oo |
|+*.*oo |
|o.+=O. |
+----[SHA256]-----+
Copy this SSH key on git server.
ssh-copy-id git@git-server.itlab.com
Output:
/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/ahmer/.ssh/id_rsa.pub"
The authenticity of host 'git-server.itlab.com (192.168.116.129)' can't be established.
ECDSA key fingerprint is SHA256:PhsrMh10ZgS3G8P/upEd5bIbjTbUW0Asbbgtsq9y3Xs.
ECDSA key fingerprint is MD5:24:af:0c:3a:33:39:2b:2a:d5:3d:64:05:a2:b6:a1:b8.
Are you sure you want to continue connecting (yes/no)? yes
/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
git@git-server.itlab.com's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'git@git-server.itlab.com'"
and check to make sure that only the key(s) you wanted were added.
Now connect with git server using ssh client.
ssh git@git-server.itlab.com
Set following git variables for the ahmer user.
git config --global user.name "ahmer"
git config --global user.email "ahmer@git-client.itlab.com"
Create a directory for keeping local git repositories.
mkdir ~/repo
cd ~/repo
Create a clone of project1 git repository.
git clone git@git-server.itlab.com:~/repo/project1 project1
Output:
Cloning into 'project1'...
warning: You appear to have cloned an empty repository.
We have created a clone of project1 repository on our local machine. You can see that currently there isn’t any file in the repository. Let’s create some files therein.
cd project1
echo "my first file" > file1.txt
cp /etc/hosts .
ls
Output:
file1.txt hosts
Add these two files to our git repository.
git add .
git commit -am "My First Commit"
Output:
[master (root-commit) 10394a7] My First Commit
2 files changed, 4 insertions(+)
create mode 100644 file1.txt
create mode 100644 hosts
Push these changes to the remote git repository at git-server.itlab.com.
git push origin master
Output:
Counting objects: 4, done.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (4/4), 362 bytes | 0 bytes/s, done.
Total 4 (delta 0), reused 0 (delta 0)
To git@git-server.itlab.com:~/repo/project1
* [new branch] master -> master
To verify the changes, connect to git-server.itlab.com via ssh and check the log.
git log
Output:
commit 10394a774797bc5c5313b9aae086aa1ab71c69b5
Author: ahmer
Date: Sun Dec 9 01:04:16 2018 -0500
My First Commit
The Kubernetes Book
$49.99 (as of June 5, 2025 18:18 GMT +00:00 – More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)Final Thoughts
By setting up a local Git server on CentOS 7, you’ve taken a major step toward gaining full control over your source code, version history, and collaboration workflows. With your own secure and private Git hosting environment, you reduce reliance on external platforms and improve performance for internal teams.
Don’t wait until a service outage or data privacy issue forces your hand—take charge of your development infrastructure now. Top development teams already host locally—why miss out? Start reaping the benefits today!
Struggling with Linux server management? I offer professional support to ensure your servers are secure, optimized, and always available. Visit my Fiverr profile to learn more!
Thank you for reading, and happy coding!
Leave a Reply
You must be logged in to post a comment.