git安装linux
‘壹’ linux怎么安装git 命令
一、使用包管理器安装GitGit已经被所有的主流Linux发行版所支持。所以安装它最简单的方法就是使用各个Linux发行版的包管理器。
1、Debian, Ubuntu, 或 Linux Mint
1
$ sudo apt-get install git
2、Fedora, CentOS 或 RHEL
1
$ sudo yum install git或$ sudo dnf install git
3、Arch Linux
1
$ sudo pacman -S git
4、OpenSUSE
1
$ sudo zypper install git
5、Gentoo
1
$ emerge --ask --verbose dev-vcs/git
二、从源码安装Git
如果由于某些原因,希望从源码安装Git,按照如下介绍操作。
1、安装依赖包
在构建Git之前,先安装它的依赖包。
1
2
3
4
//Debian, Ubuntu 或 Linux Mint
$ sudo apt-get install libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev asciidoc xmlto docbook2x
//Fedora, CentOS 或 RHEL
$ sudo yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel asciidoc xmlto docbook2x
2、从github官网下载最新版本的Git。然后在/usr下构建和安装。
注意,如果打算安装到其他目录下(例如:/opt),那就把“--prefix=/usr”这个配置命令使用其他路径替换掉。
1
2
3
4
5
$ cd git-x.x.x
$ make configure
$ 。/configure --prefix=/usr
$ make all doc info
$ sudo make install install-doc install-html install-info
‘贰’ 怎么在linux ubuntu 上安装git,id
1、yum方式安装 # yum -y install git 如果提示系统提示没有找到git包,可以采用下面的方式 2、下载Git源码包 官网: $ tar -xjvf git-1.7.4.1.tar.bz2 $ cd git-1.7.4.1/ $ make prefix=/usr/local all $ make prefix=/usr/local install
‘叁’ linux如何安装最新版本的git
一、使用包管理器安装Git
Git已经被所有的主流Linux发行版所支持。所以安装它最简单的方法就是使用各个Linux发行版的包管理器。
1、Debian, Ubuntu, 或 Linux Mint
1
$ sudo apt-get install git
2、Fedora, CentOS 或 RHEL
1
$ sudo yum install git或$ sudo dnf install git
3、Arch Linux
1
$ sudo pacman -S git
4、OpenSUSE
1
$ sudo zypper install git
5、Gentoo
1
$ emerge --ask --verbose dev-vcs/git
二、从源码安装Git
如果由于某些原因,希望从源码安装Git,按照如下介绍操作。
1、安装依赖包
在构建Git之前,先安装它的依赖包。
1
2
3
4
//Debian, Ubuntu 或 Linux Mint
$ sudo apt-get install libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev asciidoc xmlto docbook2x
//Fedora, CentOS 或 RHEL
$ sudo yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel asciidoc xmlto docbook2x
2、从github官网下载最新版本的Git。然后在/usr下构建和安装。
注意,如果打算安装到其他目录下(例如:/opt),那就把“--prefix=/usr”这个配置命令使用其他路径替换掉。
1
2
3
4
5
$ cd git-x.x.x
$ make configure
$ 。/configure --prefix=/usr
$ make all doc info
$ sudo make install install-doc install-html install-info
‘肆’ linux系统git 怎么安装
方法/步骤
1
用git --version命令检查是否已经安装
2
在CentOS5的版本,由于yum源中没有git,所以需要预先安装一系列的依赖包。在CentOS6的yum源中已经有git的版本了,可以直接使用yum源进行安装。
3
yum -y install git
但是yum源中安装的git版本是1.7.1,Github等需要的Git版本最低都不能低于1.7.2 。所以我们一般不用上面的方法,而是下载git源码编译安装。
END
编译安装git
1
首先更新系统
yum -y update
更新完成之后有6.5变成6.7了
2
安装依赖的包
yum -y install curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker
3
下载git源码并解压
$ wget https://github.com/git/git/archive/v2.3.0.zip
$ unzip v2.3.0.zip
$ cd git-2.3.0
4
编译安装:
将其安装在“/usr/local/git”目录下。
make prefix=/usr/local/git all
make prefix=/usr/local/git install
因为服务器时间不对编译的过程中报错如下图,使用ntpdate自动校正系统时间。报错“Writing perl.mak for Git make[2]: *** [perl.mak] Error 1”,请重启apache服务,service httpd restart。
5
编译完成之后使用git --version 查看git版本,居然还是1.7.1,这是因为它默认使用了"/usr/bin"下的git。
你可以用下面的命令查看git所在的路径:
$ whereis git
git: /usr/bin/git /usr/local/git /usr/share/man/man1/git.1.gz
6
我们要把编译安装的git路径放到环境变量里,让它替换"/usr/bin"下的git。为此我们可以修改“/etc/profile”文件(或者/etc/bashrc文件)。
vim /etc/profile
然后在文件的最后一行,添加下面的内容,然后保存退出。
export PATH=/usr/local/git/bin:$PATH
7
不想重启系统,使用source命令立即生效
source /etc/profile
8
然后再次使用git --version 查看git版本,发现输出2.3.0,表明安装成功。
‘伍’ 如何在线上环境linux安装git
1.首先下载git源码 自己度娘搜索下载即可。 2.xz文件解压 12xz -d git-2014-08-20.tar.xztar -xvf git-2014-08-20.tar3.安装git 12345cd git-2014-08-20/autoconf./configure --prefix=/usr/local/git/makemake install如果make的时候报错:/bin/sh: msgfmt: command not found 则需要: yum install gettext-devel 4.将git加到环境变量中 1vim /etc/profile 12export GIT_HOME=/usr/local/git/export <a href="https:///s?wd=PATH&tn=44039180_cpr&fenlei=-w9Uz4Bmy-bIi4WUvYETgN-" target="_blank" class="-highlight">PATH</a>=$<a href="https:///s?wd=PATH&tn=44039180_cpr&fenlei=-w9Uz4Bmy-bIi4WUvYETgN-" target="_blank" class="-highlight">PATH</a>:$GIT_HOME/<a href="https:///s?wd=bin&tn=44039180_cpr&fenlei=-w9Uz4Bmy-bIi4WUvYETgN-" target="_blank" class="-highlight">bin</a>这样就可以直接运行git命令了。
‘陆’ 如何搭建linux git服务器
首先我们分别在Git服务器和客户机中安装Git服务程序(刚刚实验安装过就不用安装了):
[root@linuxprobe ~]# yum install git
Loaded plugins: langpacks, proct-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Package git-1.8.3.1-4.el7.x86_64 already installed and latest version
Nothing to do
然后创建Git版本仓库,一般规范的方式要以.git为后缀:
[root@linuxprobe ~]# mkdir linuxprobe.git
修改Git版本仓库的所有者与所有组:
[root@linuxprobe ~]# chown -Rf git:git linuxprobe.git/
初始化Git版本仓库:
[root@linuxprobe ~]# cd linuxprobe.git/
[root@linuxprobe linuxprobe.git]# git --bare init
Initialized empty Git repository in /root/linuxprobe.git/
其实此时你的Git服务器就已经部署好了,但用户还不能向你推送数据,也不能克隆你的Git版本仓库,因为我们要在服务器上开放至少一种支持Git的协议,比如HTTP/HTTPS/SSH等,现在用的最多的就是HTTPS和SSH,我们切换至Git客户机来生成SSH密钥:
[root@linuxprobe ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
65:4a:53:0d:4f:ee:49:4f:94:24:82:16:7a:dd:1f:28 [email protected]
The key's randomart image is:
+--[ RSA 2048]----+
| .o+oo.o. |
| .oo *.+. |
| ..+ E * o |
| o = + = . |
| S o o |
| |
| |
| |
| |
+-----------------+
将客户机的公钥传递给Git服务器:
[root@linuxprobe ~]# ssh--id 192.168.10.10
[email protected]'s password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh '192.168.10.10'"
and check to make sure that only the key(s) you wanted were added.
此时就已经可以从Git服务器中克隆版本仓库了(此时目录内没有文件是正常的):
[root@linuxprobe ~]# git clone [email protected]:/root/linuxprobe.git
Cloning into 'linuxprobe'...
warning: You appear to have cloned an empty repository.
[root@linuxprobe ~]# cd linuxprobe
[root@linuxprobe linuxprobe]#
初始化下Git工作环境:
[root@linuxprobe ~]# git config --global user.name "Liu Chuan"
[root@linuxprobe ~]# git config --global user.email "[email protected]"
[root@linuxprobe ~]# git config --global core.editor vim
向Git版本仓库中提交一个新文件:
[root@linuxprobe linuxprobe]# echo "I successfully cloned the Git repository" > readme.txt
[root@linuxprobe linuxprobe]# git add readme.txt
[root@linuxprobe linuxprobe]# git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached ..." to unstage)
#
# new file: readme.txt
#
[root@linuxprobe linuxprobe]# git commit -m "Clone the Git repository"
[master (root-commit) c3961c9] Clone the Git repository
Committer: root
1 file changed, 1 insertion(+)
create mode 100644 readme.txt
[root@linuxprobe linuxprobe]# git status
# On branch master
nothing to commit, working directory clean
但是这次的操作还是只将文件提交到了本地的Git版本仓库,并没有推送到远程Git服务器,所以我们来定义下远程的Git服务器吧:
[root@linuxprobe linuxprobe]# git remote add server [email protected]:/root/linuxprobe.git
将文件提交到远程Git服务器吧:
[root@linuxprobe linuxprobe]# git push -u server master
Counting objects: 3, done.
Writing objects: 100% (3/3), 261 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To [email protected]:/root/linuxprobe.git
* [new branch] master -> master
Branch master set up to track remote branch master from server.
为了验证真的是推送到了远程的Git服务,你可以换个目录再克隆一份版本仓库(虽然在工作中毫无意义):
[root@linuxprobe linuxprobe]# cd ../Desktop
[root@linuxprobe Desktop]# git clone [email protected]:/root/linuxprobe.git
Cloning into 'linuxprobe'...
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.
[root@linuxprobe Desktop]# cd linuxprobe/
[root@linuxprobe linuxprobe]# cat readme.txt
I successfully cloned the Git repository
这篇是详细介绍Git的,中间有一部分是怎么去搭建,你可以看下
‘柒’ linux如何搭建git
1、环境准备
服务器:CentOS 7.3 + git (1.8.3.1)
客户端:win10 + git (2.17.0.windows.1)
2、服务器安装git
yum install -y git
3、创建git用户,管理 git服务
[root@localhost home]# useradd git
[root@localhost home]# passwd git
4、服务器创建git 仓库
设置/home/git/repository-git 为git 服务器仓库,然后把 git 仓库的 owner 修改为 git 用户。
复制代码
[root@localhost git]# mkdir repository-git
[root@localhost git]# git init --bare repository-git/
Initialized empty Git repository in /home/git/repository-gt/
[root@localhost git]# chown -R git:git repository-git/
5、客户端安装git
下载 Git for Windows,地址:https://git-for-windows.github.io/
安装完之后,可以使用 Git Bash 作为命令行客户端。
5.1、选择一个目录 F:\project\sell 作为本地仓库,右键进入Git Bash 命令行模式
初始化本地仓库:git init
5.2、尝试克隆一个服务器的空仓库到本地仓库
git clone [email protected]:/home/git/repository-gt
第一次连接到目标 Git 服务器时会得到一个提示:
The authenticity of host '192.168.116.129(192.168.116.129)' can't be established.
RSA key fingerprint is SHA256:Ve6WV/.
Are you sure you want to continue connecting (yes/no)?
选择 yes:
Warning: Permanently added '192.168.116.129' (RSA) to the list of known hosts.
此时 C:\Users\用户名\.ssh 下会多出一个文件 known_hosts,以后在这台电脑上再次连接目标 Git 服务器时不会再提示上面的语句。
‘捌’ linux 安装好git 怎么用
Git服务程序中提交数据、移除数据、移动数据、查询历史记录、还原数据及管理标签等,满足日常工作的需求。
同时还为包括了分支结构的创建与合并,遇到分支内容冲突的解决办法,动手部署Git服务器及使用Github托管服务等一些强大的功能,你可以参考下
一、在正式使用前,我们还需要弄清楚Git的三种重要模式,分别是已提交、已修改和已暂存:
已提交(committed):表示数据文件已经顺利提交到Git数据库中。
已修改(modified):表示数据文件已经被修改,但未被保存到Git数据库中。
已暂存(staged):表示数据文件已经被修改,并会在下次提交时提交到Git数据库中。
提交前的数据文件可能会被随意修改或丢失,但只要把文件快照顺利提交到Git数据库中,那就可以完全放心了,流程为:
1.在工作目录中修改数据文件。
2.将文件的快照放入暂存区域。
3.将暂存区域的文件快照提交到Git仓库中。
执行yum命令来安装Git服务程序:
[root@linuxprobe ~]# yum install -y git
Loaded plugins: langpacks, proct-id, subscription-manager
………………省略部分安装过程………………
Installing:
git x86_64 1.8.3.1-4.el7 rhel7 4.3 M
Installing for dependencies:
perl-Error noarch 1:0.17020-2.el7 rhel7 32 k
perl-Git noarch 1.8.3.1-4.el7 rhel7 52 k
perl-TermReadKey x86_64 2.30-20.el7 rhel7 31 k
………………省略部分安装过程………………
Complete!
首次安装Git服务程序后需要设置下用户名称、邮件信息和编辑器,这些信息会随着文件每次都提交到Git数据库中,用于记录提交者的信息,而Git服务程序的配置文档通常会有三份,针对当前用户和指定仓库的配置文件优先级最高:
配置文件 作用
/etc/gitconfig 保存着系统中每个用户及仓库通用配置信息。
~/.gitconfig
~/.config/git/config 针对于当前用户的配置信息。
工作目录/.git/config 针对于当前仓库数据的配置信息。
第一个要配置的是你个人的用户名称和电子邮件地址,这两条配置很重要,每次 Git 提交时都会引用这两条信息,记录是谁提交了文件,并且会随更新内容一起被永久纳入历史记录:
[root@linuxprobe ~]# git config --global user.name "Liu Chuan"
[root@linuxprobe ~]# git config --global user.email "[email protected]"
设置vim为默认的文本编辑器:
[root@linuxprobe ~]# git config --global core.editor vim
嗯,此时查看下刚刚配置的Git工作环境信息吧:
[root@linuxprobe ~]# git config --list
user.name=Liu Chuan
[email protected]
core.editor=vim
二、提交数据
我们可以简单的把工作目录理解成是一个被Git服务程序管理的目录,Git会时刻的追踪目录内文件的改动,另外在安装好了Git服务程序后,默认就会创建好了一个叫做master的分支,我们直接可以提交数据到了。
三、移除数据
有些时候会向把已经添加到暂存区的文件移除,但仍然希望文件在工作目录中不丢失,换句话说,就是把文件从追踪清单中删除。
移动数据
Git不像其他版本控制系统那样跟踪文件的移动操作,如果要修改文件名称,则需要使用git mv命令:
[root@linuxprobe linuxprobe]# git mv readme.txt introction.txt
由于字数限制,不能完全放下,如果你想好好了解,建议你看下http://www.linuxprobe.com/chapter-21.html 这个文档中有详细的用法你可以看看对你有用吗
‘玖’ 如何在 Linux 上安装 git 服务
Git 最初是一个在Linux下开发的非常流行的开源的版本控制系统(VCS)。与其他的VCS工具(如CVS或者SVN)不同,Git在某种意义上考虑的是“分布式”,你本地的Git工作目录就可以作为一个完整的版本控制库并具有版本跟踪能力。在这种模式中,每一个协作者都可以提交到本地仓库,并且如果需要的话可以有选择的推送到一个集中的版本仓库。这种可扩展性和冗余的修订控制系统是任何类型的大型协作任务中都是必须的。
一、通过包管理器安装 Git
Git 是所有主要的Linux发行版本都附带的功能。因此,安装Git的最简单的方法是使用您的Linux发行版的包管理器。
Debian, Ubuntu, or Linux Mint
$ sudo apt-get install git
Fedora, CentOS or RHEL
$ sudo yum install git
Arch Linux
$ sudo pacman -S git
OpenSUSE
$ sudo zypper install git
Gentoo
$ emerge --ask --verbose dev-vcs/git
二、从源代码安装Git
如果出于某种原因你想从源代码安装Git,你可以遵循下面的说明。
安装依赖
构建之前,首先安装Git依赖。
Debian,Ubuntu or Linux
$ sudo apt-get install libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev asciidoc xmlto docbook2x
Fedora, CentOS or RHEL
sudo yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel asciidoc xmlto docbook2x
从源代码编译Git
从 https://github.com/git/git/releases 下载最新版本的 Git,然后在 /usr 目录下构建和安装 Git。
注意,如果你想安装在一个其他的目录(如 /opt ),可以替换配置命令行中的 “--prefix=/usr ”。
$ cd git-x.x.x
$ make configure
$ ./configure --prefix=/usr
$ make all doc info
$ sudo make install install-doc install-html install-info