Introduction
Git is a version control system that supports teamwork between programmers thanks to what in computer science is namedversioning. This practice allows you to trace the changes that are performed on a specific file, such as a source code, while defining a new version for each change. If you are new to Git, reading our getting started guide on installation and first steps with Git is recommended.
Tracking the work of programmers and enabling an incremental approach to complex software development, Git has recently come in very useful, especially in software development processes. In this tutorial you will see how to install and configure Git on your Linux server with CentOS 8 to create your own private repository, without hosting restrictions, such as those of GitHub.
Installing and Configuring Server-side Git
INSTALLING GIT-SERVER
Two alternative ways of installing GIT-server are shown below.
Installation via Yum
To install the Git service via Yum, simply use this pair of commands:
$ yum update -y
$ yum install git -y
Installation from source code
Git can also be installed from the official site, where the latest release is also available.
Although the installation will take longer and will not be automatically updated by the yum package manager, this method has an advantage: greater control over the updates of your installation, as it will be linked to the CentOS repositories.
The first thing to do is to install the dependencies:
$ yum groupinstall “Development Tools”
$ yum install gettext-devel openssl-devel perl-CPAN perl-devel zlib-devel
Once the installation has been completed, open the release page link and copy the download link.By choosing the file called tar.gz, for example, the link could be simply copied by right clicking on the file and selecting "copy link".
Now it's time to download the selected file to the server, using the command:
$ wget https://github.com/git/git/archive/refs/tags/v2.32.0-rc0.tar.gz -O git.tar.gz
Once the download is complete, extract the .tar file :
$ tar -zxf git.tar.gz
Then, move to the directory of the file:
$ cd git-*
Now, it's time to check the configuration script to create through the make utility.
$ make configure
$./configure –prefix=/usr/local
It is also important to define the "prefix" of the configuration file, as it will be placed in the default folder for Linux programs.
The make utility allows you to apply configurations by compiling scripts linked to your CentOS installation.
Install make via:
$ make install
To check that everything went well, check the version of Git you just installed using the command:
$ git -version
CONFIGURING GIT REPOSITORY
The steps to configure the server side of Git are as follows:
Add a user to manage repositories, using the command:
$ useradd git
Assign a password to the newly created user:
$ passwd git
Log ing in as a git user:
$ su -git
Create a new empty repository:
$ git init –bare ~/myrepo.git
Enable post-update by uploading a sample file:
$ cd hooks/ $ cp post-update.sample post-update
Installing and Configuring Client-side Git
GIT-CLIENT INSTALLATION
On the client side, simply install Git via the yum manager :
$ yum install git -y
GIT-CLIENT CONFIGURATION
One of the first features that we suggest configuring, is to add personal information to allow commit messages to have such data attached.
$ git config –global user.name “myusername”
$ git config –global user.email “myemail@samplemail.com”
Now, create a directory to save your projects:
$ mkdir ~/dev
$ cd ~/dev
Now, try to clone the sample repository, created in the server side configuration step:
$ git clone myemail@sampleservermail.com:~/myrepo.git myrepo.git
Navigating to the repository, your first file can be now inserted:
$ cd myrepo.git
$ echo "test">samplefile.txt
Add the file to the repository:
$ git add.
Enter the changes in the commit :
$ git commit -am “My First Commit”
Submit commit changes to the remote repository on the server:
$ git push origin master
After entering the password, an output will be received to inform on the status of the process. When done, check that everything was correctly performed by opening the log file from the server:
$ git log
Conclusion
If you have correctly followed the procedures described so far and the Client-side test worked, your Git server will have been properly installed and configured and your first repository created. To learn more about how Git works, read our guide on How to manage versions with Git.
No comments:
Post a Comment