这是我参与「第三届青训营 -后端场」笔记创作活动的第3篇笔记
Git是什么
Git是一个免费且开源的分布式版本控制软件,版本控制是指一种记录一个或若干文件内容变化,以便将来查阅特定版本修订情况的系统。可以更好的关注变更,了解到每个版本的改动是什么,方便对改动的代码进行检查,预防事故发生,也能够随时切换到不同的版本,回滚误删误改的问题代码。
Git的基本使用方式
Git目录介绍
Git仓库
工作区 & 暂存区
常见Git配置
用户名配置
git config --global user.name "username"
git config --global user.email email@xxx.com
Instead of 配置
git config --global url.git@github.com:.insteadOf https://github.com/
Git命令别名配置
git config --global alias.cin "commit --amend --no-edit"
Git Remote
查看Remote
git remote -v
添加Remote
git remote add origin_ssh git@github.com:git/git.git
git remote add origin_http https://github.com/git/git.git
Git 服务器搭建
安装Git
$ yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-devel
$ yum install git
创建一个git用户组和用户,用来运行git服务:
$ groupadd git
$ useradd git -g git
创建证书登录
收集所有需要登录的用户的公钥,公钥位于id_rsa.pub文件中,把我们的公钥导入到/home/git/.ssh/authorized_keys文件里,一行一个。
如果没有该文件创建它:
$ cd /home/git/
$ mkdir .ssh
$ chmod 755 .ssh
$ touch .ssh/authorized_keys
$ chmod 644 .ssh/authorized_keys
初始化
首先我们选定一个目录作为Git仓库,假定是/home/gitrepo/runoob.git,在/home/gitrepo目录下输入命令:
$ cd /home
$ mkdir gitrepo
$ chown git:git gitrepo/
$ cd gitrepo
$ git init --bare runoob.git
Initialized empty Git repository in /home/gitrepo/runoob.git/
以上命令Git创建一个空仓库,服务器上的Git仓库通常都以.git结尾。然后,把仓库所属用户改为git:
$ chown -R git:git runoob.git
克隆仓库
$ git clone git@192.168.45.4:/home/gitrepo/runoob.git
Cloning into 'runoob'...
warning: You appear to have cloned an empty repository.
Checking connectivity... done.
192.168.45.4 为 Git 所在服务器 ip ,你需要将其修改为你自己的 Git 服务 ip。
这样我们的 Git 服务器安装就完成。