Ubuntu Git安裝與使用
來自: http://blog.csdn.net/yhl_leo/article/details/50760140
本系列文章由 @yhl_leo 出品,轉載請注明出處。
文章鏈接: http://blog.csdn.net/yhl_leo/article/details/50760140
本文整理和歸納了關于Ubuntu中Git安裝與使用的資源,希望對大家有所幫助。
1 安裝
安裝方式主要有兩種,即通過Apt
和source
:
1.1 通過Apt
安裝:
官網上提供的命令是:
$ sudo add-apt-repository ppa:git-core/ppa
中間暫停時,按回車鍵Enter
繼續安裝。
$ sudo apt-get update $ sudo apt-get install git
安裝下載完成后,可以使用下面的命令行,確認git
的版本:
$ git --version
1.2 通過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
安裝位置重裝和重編譯新的版本(會將舊版本覆蓋掉)。
2 git
入門
2.1 配置git
首先,是指定用戶名和郵箱:
$ git config --global user.name "Your Name" $ git config --global user.email "youremail@domain.com"
可以如下查看配置信息:
$ git config --list
2.2 創建一個本地repository
創建一個名為myGitTest
的repository
:
$ git init myGitTest
然后切換,文件路徑到myGitTest
:
$ cd myGitTest
依次添加文件README
和sample.cpp
$ gedit README$ gedit sample.cpp</pre>
在
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; }</pre>
將這兩個文件通過
git
添加到剛剛創建的myGitTest
:$ git add README$ git add smaple.c</pre>
現在,將
myGitTest
的變化更新情況提交:$ git commit -m "create a git project"
2.3 同步到GitHub
在GitHub個人賬戶中,創建一個
repository
(我已經創建過了,所以會提示已經存在):
將新創建的
repository
的URL拷貝:
使用下面的命令,將本地的
repository
提交到GitHub:$ git remote add origin https://github.com/yhlleo/myGitTest.git$ git push origin master</pre>
接著會提示輸入GitHub的賬戶名和密碼,輸入就可以完成:
登陸到GitHub上,打開
myGitTest
如下:</div>