Ubuntu Git安装与使用


本系列文章由 @yhl_leo 出品。转载请注明出处。
文章链接: http://blog.csdn.net/yhl_leo/article/details/50760140


本文整理和归纳了关于Ubuntu中Git安装与使用的资源,希望对大家有所帮助。

1 安装

安装方式主要有两种,即通过Aptsource

1.1 通过Apt安装:

官网上提供的命令是:

$ sudo add-apt-repository ppa:git-core/ppa

Git1

中间暂停时,按回车键Enter继续安装。

$ sudo apt-get update
$ sudo apt-get install git  

安装下载完毕后,能够使用以下的命令行。确认git的版本号:

$ git --version 

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:

git_version_2

复制下压缩文件的下载链接(Downloadsbutton鼠标右键):

git_down_address

使用命令行下载:

$ 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项目中拷贝:

copy_address

然后像上面一样,编译源代码:

$ make prefix=/usr/local all
$ sudo make prefix=/usr/local install

就会在git安装位置重装和重编译新的版本号(会将旧版本号覆盖掉)。

2 git入门

2.1 配置git

首先,是指定username和邮箱:

$ git config --global user.name "Your Name"
$ git config --global user.email "youremail@domain.com"

能够例如以下查看配置信息:

$ git config --list

2.2 创建一个本地repository

创建一个名为myGitTestrepository:

$ git init myGitTest

git_init

然后切换。文件路径到myGitTest

$ cd myGitTest

依次加入文件READMEsample.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.cpp

如今,将myGitTest的变化更新情况提交:

$ git commit -m "create a git project"

git pro

2.3 同步到GitHub

在GitHub个人账户中。创建一个repository(我已经创建过了。所以会提示已经存在):

mygittest

将新创建的repository的URL拷贝:

git path

使用以下的命令。将本地的repository提交到GitHub:

$ git remote add origin https://github.com/yhlleo/myGitTest.git

$ git push origin master

接着会提示输入GitHub的账户名和password。输入就能够完毕:

git commit

登陆到GitHub上,打开myGitTest例如以下:

github


近期看到一个不错的在线教程,认为有必要分享一下:IissNan/Pro Git,想深入了解Git的话。值得一读~

原文地址:https://www.cnblogs.com/blfbuaa/p/7372772.html