本文整理和歸納了關於Ubuntu中Git安裝與使用的資源,希望對大家有所幫助。
安裝方式主要有兩種,即通過Apt
和source
:
Apt
安裝:官網上提供的命令是:
$ sudo add-apt-repository ppa:git-core/ppa
中間暫停時,按回車鍵Enter
繼續安裝。
$ sudo apt-get update
$ sudo apt-get install git
安裝下載完成後,可以使用下面的命令行,確認git
的版本:
$ git --version
Source
安裝首先,安裝一些git
依賴的軟件:
$ sudo apt-get install build-essential libssl-dev libcurl4-gnutls-dev libexpat1-dev gettext unzip
安裝完成後,可以在GitHub上公布的Git Project,選擇Tags
中的最新版本2.7.2:
復制下壓縮文件的下載鏈接(Downloads按鈕鼠標右鍵):
使用命令行下載:
$ wget https://github.com/git/git/archive/v1.9.2.zip -O git.zip
解壓,並路徑轉換到git
下:
$ unzip git.zip
$ cd git-*
編譯源碼:
$ make prefix=/usr/local all
$ sudo make prefix=/usr/local install
編譯完成後,同樣可以利用上述的語句查看git
版本。
如果,後面還想繼續更新,可以這樣:
$ git clone https://github.com/git/git.git
訪問的鏈接(URL)可以在上述的GitHub項目中拷貝:
然後像上面一樣,編譯源碼:
$ make prefix=/usr/local all
$ sudo make prefix=/usr/local install
就會在git
安裝位置重裝和重編譯新的版本(會將舊版本覆蓋掉)。
git
入門git
首先,是指定用戶名和郵箱:
$ git config --global user.name "Your Name"
$ git config --global user.email "[email protected]"
可以如下查看配置信息:
$ git config --list
repository
創建一個名為myGitTest
的repository
:
$ git init myGitTest
然後切換,文件路徑到myGitTest
:
$ cd myGitTest
依次添加文件README
和sample.cpp
$ gedit README
$ gedit sample.cpp
在README
文件內隨便寫入一些內容:
This is my first Git and GitHub test conducted on my Ubuntu Wily system.
同理,在sample.cpp
中寫入一段代碼:
#include <iostream>
int main()
{
std::cout << "Hello Git!" << std::endl;
return 0;
}
將這兩個文件通過git
添加到剛剛創建的myGitTest
:
$ git add README
$ git add smaple.c
現在,將myGitTest
的變化更新情況提交:
$ git commit -m "create a git project"
在GitHub個人賬戶中,創建一個repository
(我已經創建過了,所以會提示已經存在):
將新創建的repository
的URL拷貝:
使用下面的命令,將本地的repository
提交到GitHub:
$ git remote add origin https://github.com/yhlleo/myGitTest.git
$ git push origin master
接著會提示輸入GitHub的賬戶名和密碼,輸入就可以完成:
登陸到GitHub上,打開myGitTest
如下:
Git 教程系列文章:
GitHub 使用教程圖文詳解 http://www.linuxidc.com/Linux/2014-09/106230.htm
Git 標簽管理詳解 http://www.linuxidc.com/Linux/2014-09/106231.htm
Git 分支管理詳解 http://www.linuxidc.com/Linux/2014-09/106232.htm
Git 遠程倉庫詳解 http://www.linuxidc.com/Linux/2014-09/106233.htm
Git 本地倉庫(Repository)詳解 http://www.linuxidc.com/Linux/2014-09/106234.htm
Git 服務器搭建與客戶端安裝 http://www.linuxidc.com/Linux/2014-05/101830.htm
Git 概述 http://www.linuxidc.com/Linux/2014-05/101829.htm
分享實用的GitHub 使用教程 http://www.linuxidc.com/Linux/2014-04/100556.htm
Git從入門到學會 http://www.linuxidc.com/Linux/2016-10/135872.htm
Git基本操作詳解 http://www.linuxidc.com/Linux/2016-10/135691.htm
Git 的詳細介紹:請點這裡
Git 的下載地址:請點這裡