Install Git under Linux

Source: Internet
Author: User

Git is not installed by default in Ubuntu12.04. You need to install it yourself.

1. Install Git1.1 Ubuntu12.04

Can be installed using the Apt-get mode, or you can download the source code installation "1", we use Apt-git installation here.

However, due to the older version of the direct use sudo apt-get install git installation, we refer to the PPA source given in "2".

sudo add-apt-repository ppa:git-core/ppasudo apt-get updatesudo apt-get install git

After the installation is complete, check that the installation is successful

Git--version

Displays Git version 2.1.1, indicating that the installation was successful.

1.2 CentOS6.6

In the CentOS5 era, there was no git in the Yum source, so a series of dependencies needed to be preinstalled. However, there is already a git version in the CentOS6 Yum source, which can be installed directly using the Yum source.

$ sudo yum install git

But the GIT version installed in the Yum source is 1.7.1, too old, and the git version needed for GitHub should be no less than 1.7.2. So we generally do not use the above method. Instead, download the git source code and compile the installation.

The steps to compile the installation are "4":

(1) First update the system

Yum Update

(2) Install dependent packages

Perl-extutils-makemaker

(3) Download git source code and unzip it

wget https://unzip v2.  3.0.Zip$ cd git-2.3.  0      

(4) Compile and install

Install it under the "/usr/local/git" directory.

Make prefix=/usr/local/git allinstall 

(5) If you use Git--version to view the git version, you find Git is still 1.7.1 version. This is because it uses git under "/usr/bin" by default.

You can use the following command to see the path to git:

Whereis gitgit:/usr/bin/git/usr/local/git/usr/share/man/man1/git.  1.gz  

(6) We will put the compiled git path into the environment variable, and let it replace git under "/usr/bin". For this we can modify the "/etc/profile" file (or/ETC/BASHRC file).

sudo vim/etc/profile

Then, in the last line of the file, add the following, and then save the exit.

Export Path=/usr/local/git/bin: $PATH

(7) Apply the modification using the source command.

Source/etc/profile

(8) Then use git--version again to view the Git version and find out 2.3.0, indicating that the installation was successful.

2. Set up Git

(1) Set user name and email.

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

At this point, a new. gitconfig file is created in the home directory

3. Add SSH Keys to your GitHub account

A git server that accesses the SSH protocol as a public key authentication does not need to enter a password and is more secure. (When accessing the HTTP protocol's GIT server, such as committing changes, you need to enter a password each time.) )

(1) Create SSH key

$ ssh-keygen-t rsa-c "[Email protected]"

The system will prompt the key to save the location (typically the ~/.SSH directory) and specify the password, keep the default, three consecutive times to enter.

(2) Copy SSH Key

Then use VIM to open the file, id_rsa.pub the contents of the file, paste into the GitHub account management of the Add SSH key interface.

Vim ~/.ssh/id_rsa.pub

(3) Add to GitHub

Login github-> Accounting Settings icon--ssh key-> add ssh key-> fill in the name of the SSH key (which can be easily differentiated by yourself) and then copy the ~/.ssh/id_ Rsa.pub file content sticky, add Key button added.

(4) test

[Email protected]
4. Submit changes for repository on GitHub

(1) Git clone already exists on GitHub repository. (In the new ~/mytestfolder directory)

git clone https://github.com/zhchnchn/ZhchnchnTest.git

(2) Modify a file and then submit

Vim readme.mdgit statusgit Add readme.mdgit statusgit commit-m "Edit by Workubuntu 1204" git statusgit Remote Add Origin H Ttps://github.com/zhchnchn/zhchnchntest.git

Errors will be reported at this time:

Fatal:remote origin already exists.

Workaround "3":

$ git Remote RM origin

Then execute git remote add Origin https://github.com/zhchnchn/ZhchnchnTest.git again

(3) After that, you need to push the changes to GitHub

Git push-u Origin Master

After executing this command, you will be asked to enter the user name and password for your GitHub account.

(4) Once the submission is complete, review the repository on GitHub and find the content modified successfully.

Refer

"1" How to Install Git on Ubuntu 14.04 (https://www.digitalocean.com/community/tutorials/how-to-install-git-on-ubuntu-14-04)

"2" Installing Latest version of Git in Ubuntu (http://stackoverflow.com/questions/19109542/ Installing-latest-version-of-git-in-ubuntu)

Install git under "3" Ubuntu12.04 (http://blog.csdn.net/biosd/article/details/9115837)

"4" CentOS6.6 source installation git-2.3.0 (http://blog.csdn.net/goritcly/article/details/43878209) (http://www.centoscn.com/ image-text/install/2015/0225/4735.html)

Install Git under Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.