FoxuTech

Install and Configure GIT server in Redhat/CentOS

Install and Configure GIT server

By far, the most widely used modern version control system in the world today is Git. Git is a mature, actively maintained open source project originally developed in 2005 by Linus Torvalds, the famous creator of the Linux operating system kernel. A staggering number of software projects rely on Git for version control, including commercial projects as well as open source. Developers who have worked with Git are well represented in the pool of available software development talent and it works well on a wide range of operating systems and IDEs (Integrated Development Environments).

Having a distributed architecture, Git is an example of a DVCS (hence Distributed Version Control System). Rather than have only one single place for the full version history of the software as is common in once-popular version control systems like CVS or Subversion (also known as SVN), in Git, every developer’s working copy of the code is also a repository that can contain the full history of all changes.

In addition to being distributed, Git has been designed with performance, security and flexibility in mind.

Install GIT

We can install GIT using yum in RedHat/centOS and apt-get in debian.

On RedHat/CentOS:

# yum install git

On Debian:

# apt-get install git

Configuration

Git is installed by default under /usr/bin/git. Once you’ve installed GIT, verify it as shown below.

# whereis git

git: /usr/bin/git

# git –version

git version 1.8.3.1

# git –help.

Once verified, now we need to specify your username and email address to your GIT repository using “git config” as shown below.

git config –global user.name “GIT Admin”

git config –global user.email admin@foxutech.com

Verify the git configuration information as shown below.

# git config –list

user.name=GIT Admin

user.email=admin@foxutech.com

core.repositoryformatversion=0

core.filemode=true

core.bare=false

core.logallrefupdates=true

This information is stored in the .gitconfig file under your home directory.

# cat ~/.gitconfig

[user]

name = GIT Admin

email = admin@foxutech.com

Create a Project

You can make any of your local directory as a GIT project (i.e repository). For example, if your project is located under /home/admin/projects/gitproject, you can make that as your GIT project. First, cd to that directory, and execute git init as shown below.

# cd /home/admin/projects/gitproject

# git init

Initialized empty Git repository in /home/admin/projects/gitproject/.git/

This will create a .git directory under your project folder under .git directory.

Note: If you are sysadmin, who is trying to create a GIT central repository for your company, from where developers can download the projects, you may want to create a username called ‘git’ and organize all your projects under this account. For example: /home/git/project1, /home/git/project2, etc. Once you have the project organized, cd to the project directory, and do ‘git init’ from there as git user.

Add and Commit files to the Project

Once you created and initiated the project using “git init”, add the files located under this project directory, using “git add”.

If there are different types of files under your project directory, and you want GIT to manage only certain types of files, add only those to the GIT as shown below. This example adds only the *.java and *.c files.

# git add *.java

# git add *.c

Typically you would like to add all the files under the project directory to the GIT project. Just do “git add .” which will add all the files in the current directory and all the sub-directories to the GIT project.

# git add .

Once you’ve added the files to the repository, you should commit those files, as shown below.

# git commit -m ‘Initial upload of the project’

create mode 100755 MyGitProject.java

create mode 100755 git/ui/Gitman.java

create mode 100755 git/ui/initGIT.java

create mode 100755 git/tools/gitpro.java

create mode 100755 git/tools/final.java

..

If you didn’t specify your username and email address using “git config” as explained above, you’ll get the following error message.

# git commit -m ‘Initial upload of the project’

** Please tell me who you are.

Run

git config –global user.email “you@example.com”

git config –global user.name “Your Name”

to set your account’s default identity.

Omit –global to set the identity only in this repository.

fatal: empty ident   not allowed

Make Changes and Commit the File

You’ve installed GIT, created a project repository, committed all the files to the GIT project.

Now it is time to start making some changes to a file and commit it to the repository.

# vim MyProject.java

Once you’ve modified a file locally, you can view the changes. i.e The difference between your local copy, and the copy already committed in the GIT project using “git diff” as shown below.

# git diff

diff –git a/MyGitProject.java b/MyGitProject.java

index 6166ed1..fd82d32 100644

— a/MyGitProject.java

+++ b/MyGitProject.java

@@ -2,7 +2,7 @@

–   public counter=10

+   public counter=55

Before try this in production, make sure you were trying staging (testing) environment

# git add MyGitProject.java

When you perform commit, it will open your default editor, where you can enter the comment. Once you save your comment and exit the editor, it will commit the file to the GIT project and display the following message.

# git commit

[master 80f10a9] Added password strength meter functionality

1 files changed, 56 insertions(+), 7 deletions(-)

FYI : git commit –a will do commit and add at sametime

View Status and Commit Logs

To check the status, use below comment,

# git status

# On branch master

nothing to commit (working directory clean)

If you’ve made changes to a file, and not committed yet, you’ll see the following message.

# git status

# On branch master

# Changes not staged for commit:

#   (use “git add …” to update what will be committed)

#   (use “git checkout — …” to discard changes in working directory)

#

#       modified:   MyGitProject.java

#

no changes added to commit (use “git add” and/or “git commit -a”)

You can also view the history of a file as shown below.

# git log MyGitProject.java

commit c919ced7f42f4bc06d563c1a1eaa107f2b2420d5

Author: GIT Admin

Date:   Sat Aug 13 22:54:57 2011 -0700

Added password strength meter functionality

commit c141b7bdbff429de35e36bafb2e43edc655e9957

Author: GIT Admin

Date:   Sat Aug 13 20:08:02 2011 -0700

Initial upload of the project

 

Exit mobile version