天天看點

Git的環境搭建與安裝一、Git安裝二、基本配置及生成ssh key

版權聲明:本文為部落客原創文章,轉載請注明出處http://blog.csdn.net/u013132758。 https://blog.csdn.net/u013132758/article/details/51039013

git是很好的一個版本控制工具,可以執行liunx指令,有git環境後windows系統就可以進行shell指令操作,就可以添加其他liunx輔助軟體進行執行,git也代碼庫管理工具,無論是上傳,下載下傳代碼都可以使用git的環境,起到很好應用效果。下面為大家介紹Git在Linux和Windows環境下的配置。

一、Git安裝

1、Linux 作業系統環境

如果使用的是GNU/

Linux 發行版Debian基本apt-get指令就可以搞定一切。

[ubuntu ~]$ sudo apt-get install git-core
[sudo] password for ubuntu:

[ubuntu ~]$ git --version
git version 1.8.1.2           

而且,如果使用的是基于RPM的GNU/ Linux發行版使用yum指令,(不常見)如下:

[CentOS ~]$
su -
Password:

[CentOS ~]# yum -y install git-core

[CentOS ~]# git --version
git version 1.7.1           

2、windows環境

在Git官網根據作業系統的位數下載下傳.exe檔案。輕按兩下執行,根據需要點next。直至安裝完成。如下:

安裝完成後會有三個應用程式如下:

他們分别是圖形界面,分支管理,及指令視窗。

二、基本配置及生成ssh

key

Git

安裝完成後

設定使用者名

此資訊用于Git的每個送出。

[jerry@CentOS project]$ git config --global user.name "Jerry Mouse"

設定電子郵件ID

[jerry@CentOS project]$ git config --global user.email "[email protected]"

避免PULLING送出合并 

先從遠端資源庫的最新變化,如果這些變化是不同的,預設情況下,Git 建立合并送出。我們可以通過以下設定來避免這種。

jerry@CentOS project]$ git config --global branch.autosetuprebase always

顔色高亮

下面的指令使顔色突出顯示在控制台的Git。

[jerry@CentOS project]$ git config --global color.ui true

jerry@CentOS project]$ git config --global color.status auto

[jerry@CentOS project]$ git config --global color.branch auto

設定預設編輯器

預設情況下,Git的使用系統預設取自VISUAL或EDITOR環境變量的編輯器。我們可以設定一個不同的使用git 配置。

[jerry@CentOS project]$ git config --global core.editor vim

設定預設的合并工具

Git不會提供一個預設的合并工具整合到工作樹沖突的更改。我們可以設定預設的合并工具,通過啟用以下設定。

[jerry@CentOS project]$ git config --global merge.tool vimdiff

列出GIT設定

為了驗證自己的Git設定本地存儲庫使用git 的config-list指令,如下所示。

[jerry@CentOS ~]$ git config --list

上面的指令會産生以下結果。

user.name=Jerry Mouse

[email protected]

push.default=nothing

branch.autosetuprebase=always

color.ui=true

color.status=auto

color.branch=auto

core.editor=vim

merge.tool=vimdiff

生成SSH

1.檢視是否已經有了ssh密鑰:cd

~/.ssh

如果沒有密鑰則不會有此檔案夾,有則備份删除

2.生存密鑰:

$ ssh-keygen -t rsa -C “[email protected]

按3個回車,密碼為空。

Your identification has been saved in /home/tekkub/.ssh/id_rsa.

Your public key has been saved in /home/tekkub/.ssh/id_rsa.pub.

The key fingerprint is:

………………

最後得到了兩個檔案:id_rsa和id_rsa.pub

3.添加密鑰到ssh:ssh-add 檔案名

或者是

用指令  cat ~/.ssh/id_rsa.pub。檢視公玥。。。。

需要之前輸入密碼。

4.在github上添加ssh密鑰,這要添加的是“id_rsa.pub”裡面的公鑰。

打開https://github.com/ ,登陸,然後添加ssh。

5.測試:ssh

[email protected]

如果測試通過,就可以使用git了,可以clone,pull,push。。。。。等。具體操作指令将在後面幾篇部落格中詳細為大家介紹。