git私服搭建中篇 - 简单 git 版本管理

一、前言

我之前大部分使用 svn,但是 看资料 git 更好, 所以私服打算 使用 git.

分布式的一个好处是代码变化push好的仓库数据,最少保留两份:本地一份和服务器一份,不怕丢。, 本地仓库 和 远程仓库

和SVN中心集中式文件管理的仓储管理不同,Git所有操作都可以无服务器存在,你可以只在本地都能完成所有git操作,可以在目录之间实现clone、push和pull等需要服务器端的操作。设置权限和通讯方法后,Git客户端直接也完全可以实现这些操作(git 可以 clone 本地库, 可以克隆 局域网其他库)。所以我们说Git是天然分布式,无需中心服务器 介入。

Git的四个区(工作区、暂存区、本地仓库区和远程仓库区) 工作区 add 到 暂存区, commit 到本地仓库, push 到远程仓库

二、centos git server 搭建

经过前篇 我们的 centos 已经获取到 独立 ip了, 然后我们通过 ssh 工具 xshell 连接到 centos

先执行 yum remove git 卸载我们系统中可能存在的 git , 因为 yum 安装的 git 版本比较低

2.1 安装 git

https://github.com/git/git/releases 可以查询到最新版本 git

在这里插入图片描述

2.1.1. 下载 git 包
# yum install -y curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-devel
# wget https://github.com/git/git/archive/v2.13.2.tar.gz
# tar zxf v2.13.2.tar.gz
2.1.2. 安装git,配置环境变量
# cd git-2.13.2
# make prefix=/usr/local/git all
# make prefix=/usr/local/git install
# echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/bashrc
# source /etc/bashrc    // 实时生效

# git --version
git version 2.13.2
2.1.3. 添加一个git用户,为安全起见禁用shell登录
# useradd git

// 为安全起见,禁用 git 用户的 shell 登录
# vim /etc/passwd
// 修改 git 用户的 shell 为 git-shell,路径使用 which git-shell 查看
// 找到如下一行
git:x:1001:1001::/home/git:/bin/bash
// 修改成如下
git:x:1001:1001::/home/git:/usr/local/git/bin/git-shell

2.2 创建 git 库

2.2.1. 创建 web-font.git 库

创建 bare git 库 git init --bar web-font.git
修改repository所有者 chown -R git:git ./web-font.git/

[root@izj6c5ni08zecfihgfhnr1z repository]# git init --bar web-font.git
Initialized empty Git repository in /srv/git/repository/web-font.git/
[root@izj6c5ni08zecfihgfhnr1z repository]# ll
total 8
drwxr-xr-x 7 root root 4096 Aug 22 10:45 react.git
drwxr-xr-x 7 root root 4096 Aug 22 20:29 web-font.git
[root@izj6c5ni08zecfihgfhnr1z repository]# chown -R git:git ./web-font.git/
2.2.2. 本地机器 clone web-front.git
Administrator@DESKTOP-07NFHB4 MINGW64 ~/Desktop/git-private-server
$ git clone git@47.75.218.230:/srv/git/repository/web-front.git
Cloning into 'web-front'...
git@47.75.218.230's password:
fatal: '/srv/git/repository/web-front.git' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

竟然报错了, 因为我们使用 useradd git 创建 git 用户的时候并没有设置密码

centos上 设置 git 用户密码

passwd username 即可

[root@izj6c5ni08zecfihgfhnr1z repository]# passwd git
Changing password for user git.
New password: 
BAD PASSWORD: The password is shorter than 8 characters
Retype new password: 
passwd: all authentication tokens updated successfully.

成功 clone 仓库

在这里插入图片描述

参考连接

需要通过公钥私钥 访问git 库 可以看下

CSDN-git私服
简书-git私服

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值