如何在centos6.4上安装git How To Install Git on a CentOS 6.4 VPS

https://www.digitalocean.com/community/articles/how-to-install-git-on-a-centos-6-4-vps


How To Install Git on a CentOS 6.4 VPS

TAGGED IN:  CENT OS,  GETTING STARTED,  GIT

Introduction

Git is an open source, distributed version control system developed by Linus Torvalds, the creator of Linux. It features trivial branching and merging, the ability to manage multiple remote repositories for a single project, and truly distributed development.

Although git is wonderful at managing large, complex projects with perhaps hundreds or thousands of contributors, it can also work extremely well for small projects with one person or a small team. This flexibility makes it a great choice for implementing version and source control for software projects of any size.

In this article, we will cover how to install git on a CentOS 6.4 server using yum, the CentOS package manager. We will then show how to install git from source in case you would like to benefit from the latest improvements.

How To Install Git Using Yum

As is the case with most Linux distributions, git is available from CentOS's default repositories. We can install the package maintainer's most recent version with:

sudo yum install git

You will have to type "y" to confirm the installation. Afterwards, git will be installed and ready to use.

How To Install Git from Source on CentOS

If you want the most recent version of git, you are better off downloading the most recent version from source and compiling from there.

The version in the CentOS repositories as of this writing is 1.7.1, while the latest version of git is 1.8.4, which is a significant difference.

First, we need to download compilation tools for CentOS using the following command:

sudo yum groupinstall "Development Tools"

This will install the make tools and compilers needed to transform source code into binary executables.

Once this is complete, we will need to install some extra dependencies that git needs either to build or run:

sudo yum install zlib-devel perl-ExtUtils-MakeMaker asciidoc xmlto openssl-devel

Once these are installed, you can obtain the latest version of git from the code hosted on github.com:

cd ~
wget -O git.zip https://github.com/git/git/archive/master.zip

Unzip the archive and change into the project directory:

unzip git.zip
cd git-master

We can figure the package, build the executables and documentation, and then install it with the following set of commands:

make configure
./configure --prefix=/usr/local
make all doc
sudo make install install-doc install-html

To update git at a later date, you can actually use git! Clone the git repository on github into a new directory and then build and install it, as before:

git clone git://github.com/git/git

How To Set Up Git

When you commit changes with git, it embeds your name and email address into the commit message in order to easily track changes.

If we do not configure this information ourselves, git may try to guess these values (probably incorrectly) by using your Linux username and hostname.

Give git the values you wish to use for these parameters with these commands:

git config --global user.name "Your Name Here"
git config --global user.email "[email protected]"

The configuration changes will be stored in a file in your home directory. You can see them with a normal text editor:

nano ~/.gitconfig
[user]
        name = Your Name Here
        email = [email protected]

You can also view this information by querying git itself for the current configuration settings:

git config --list
user.name=Your Name Here
[email protected]

As mentioned earlier, if you forget to set up these steps, git may try to fill in these values automatically:

[master 0d9d21d] initial project version
 Committer: root 
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:

    git config --global user.name "Your Name"
    git config --global user.email [email protected]

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

Depending on your version of git, it may fail entirely:

git commit
*** Please tell me who you are.

Run

  git config --global user.email "[email protected]"
  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 name (for ) not allowed

As you can see, git is very good about telling you exactly what you should be doing.

Conclusion

You now have git installed and can start learning some basic usage. We have a few tutorials that may be good to look at:

  • How To Use Git Effectively

  • How To Use Git Branches

Git is a tool that becomes immediately useful with a basic understanding, and continues to offer advantages as your knowledge grows.

By Justin Ellingwood

你可能感兴趣的:(git,centos6.4)