如何搭建自己的git服务器

news2024/10/6 6:40:36

GitHub,Gitee 想来大家都用过,我们的代码就是托管在这些平台上的。因此,你可能好奇为什么我们不自己搭建一个 git 呢服务器?下面,就开始教大家如何一步步搭建自己的 git 服务器(试验成功的那一刻还是很让人激动的)。

我自己的虚拟机是 centOS7 的,首先肯定要安装 git 和 git-daemon,可以使用自带的 yum 进行安装。

yum install -y git
yum install -y git-daemon

复制

[root@master ~]# git --version
git version 2.28.0

[root@master ~]# yum install -y git-daemon
Loaded plugins: fastestmirror
Determining fastest mirrors
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Running transaction
  Installing : perl-Git-1.8.3.1-23.el7_8.noarch                                                                   

  ...

Installed:
  git-daemon.x86_64 0:1.8.3.1-23.el7_8                                                                                 

Dependency Installed:
  git.x86_64 0:1.8.3.1-23.el7_8                          perl-Git.noarch 0:1.8.3.1-23.el7_8                          

Complete!

复制

虚拟机服务端

创建 git 目录

[root@master ~]# mkdir git
[root@master ~]# cd git
[root@master git]# pwd
/root/git

复制

创建 git 仓库文件夹

[root@master git]# mkdir test-repo.git
[root@master git]# cd test-repo.git/
[root@master test-repo.git]# 

复制

初始化空目录仓库

[root@master test-repo.git]# git --bare init
Initialized empty Git repository in /root/git/test-repo.git/
[root@master test-repo.git]# ls -l
total 16
drwxr-xr-x. 2 root root    6 Sep 15 22:56 branches
-rw-r--r--. 1 root root   66 Sep 15 22:56 config
-rw-r--r--. 1 root root   73 Sep 15 22:56 description
-rw-r--r--. 1 root root   23 Sep 15 22:56 HEAD
drwxr-xr-x. 2 root root 4096 Sep 15 22:56 hooks
drwxr-xr-x. 2 root root   21 Sep 15 22:56 info
drwxr-xr-x. 4 root root   30 Sep 15 22:56 objects
drwxr-xr-x. 4 root root   31 Sep 15 22:56 refs

复制

修改仓库的 mod 权限

[root@master test-repo.git]# cd ..
[root@master git]# chmod 770 test-repo.git/ -R
[root@master git]# chmod 775 test-repo.git/ -R

复制

设置默认新建的文件和文件夹同属于其父目录的用户组

[root@master git]# chmod g+s test-repo.git -R
[root@master git]# set -m g:root:rwx test-repo.git
[root@master git]# 

复制

开启 git daemon 服务

[root@master git]# git daemon --verbose --export-all --base-path=/root/git/test-repo.git/
[3680] Ready to rumble

复制

本地机客户端

创建目录并初始化成仓库

Administrator@PC-20200713AJJH MINGW64 /d/MyProject
$ mkdir test-repo
Administrator@PC-20200713AJJH MINGW64 /d/MyProject
$ cd test-repo
Administrator@PC-20200713AJJH MINGW64 /d/MyProject/test-repo
$ git init
Initialized empty Git repository in D:/MyProject/test-repo/.git/

Administrator@PC-20200713AJJH MINGW64 /d/MyProject/test-repo (master)
$

复制

查看 config 文件

文件在仓库的 .git 目录下。

Administrator@PC-20200713AJJH MINGW64 /d/MyProject/test-repo (master)
$ cd .git/

Administrator@PC-20200713AJJH MINGW64 /d/MyProject/test-repo/.git (GIT_DIR!)
$ vim config
[core]
        repositoryformatversion = 0
        filemode = false
        bare = false
        logallrefupdates = true
        symlinks = false
        ignorecase = true

复制

关联远程仓库

Administrator@PC-20200713AJJH MINGW64 /d/MyProject/test-repo/.git (GIT_DIR!)
$ git remote add origin ssh://192.168.128.139/root/git/test-repo.git

复制

修改 config 文件

我用的 root 账号登录的,所以 url 也改成 root@192.168.128.139 的形式:

[core]
        repositoryformatversion = 0
        filemode = false
        bare = false
        logallrefupdates = true
        symlinks = false
        ignorecase = true
[remote "origin"]
        url = ssh://root@192.168.128.139/root/git/test-repo.git
        fetch = +refs/heads/*:refs/remotes/origin/*

复制

git commit 一些东西

Administrator@PC-20200713AJJH MINGW64 /d/MyProject/test-repo/.git (GIT_DIR!)
$ cd ..

Administrator@PC-20200713AJJH MINGW64 /d/MyProject/test-repo (master)
$ touch test.txt

Administrator@PC-20200713AJJH MINGW64 /d/MyProject/test-repo (master)
$ vim test.txt
hello world

Administrator@PC-20200713AJJH MINGW64 /d/MyProject/test-repo (master)
$ git add test.txt
warning: LF will be replaced by CRLF in test.txt.
The file will have its original line endings in your working directory.

Administrator@PC-20200713AJJH MINGW64 /d/MyProject/test-repo (master)
$ git commit -m "first commit :)"
[master (root-commit) a1e4f83] first commit :)
 1 file changed, 1 insertion(+)
 create mode 100644 test.txt

复制

关联分支并推送

Administrator@PC-20200713AJJH MINGW64 ~/Desktop/test-repo (master)
$ git remote -v
origin  ssh://root@192.168.128.139/root/git/test-repo.git (fetch)
origin  ssh://root@192.168.128.139/root/git/test-repo.git (push)

Administrator@PC-20200713AJJH MINGW64 /d/MyProject/test-repo (master)
$ git push -u origin master
root@192.168.128.139's password:
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 217 bytes | 217.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To ssh://192.168.128.139/root/git/test-repo.git
 * [new branch]      master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.

复制

虚拟机服务端

新建一个终端查看 push 记录

因为刚才那个终端还跑着 git-daemon 服务,所以先不要关掉(后来发现好像关掉了也不影响,不知道是为什么)。

[root@master git]# cd test-repo.git/
[root@master test-repo.git]# pwd
/root/git/test-repo.git
[root@master test-repo.git]# git log
commit a1e4f83292ac8d9128c94a402ce2ada752fb14aa (HEAD -> master)
Author: 2392863668 <2392863668@qq.com>
Date:   Tue Sep 15 23:16:34 2020 +0800

    first commit :)

复制

可以看到,服务端已经成功接收到了。

当然,客户端可以多推送一些上来,服务端都是可以接收到的。

本地机客户端

再次推送

Administrator@PC-20200713AJJH MINGW64 /d/MyProject/test-repo (master)
$ vim test.txt

Administrator@PC-20200713AJJH MINGW64 /d/MyProject/test-repo (master)
$ git add test.txt
warning: LF will be replaced by CRLF in test.txt.
The file will have its original line endings in your working directory.

Administrator@PC-20200713AJJH MINGW64 /d/MyProject/test-repo (master)
$ git commit -m "second commit"
[master ec56e9e] second commit
 1 file changed, 1 insertion(+)

Administrator@PC-20200713AJJH MINGW64 /d/MyProject/test-repo (master)
$ git push
root@192.168.128.139's password:
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Writing objects: 100% (3/3), 261 bytes | 261.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To ssh://192.168.128.139/root/git/test-repo.git
   a1e4f83..ec56e9e  master -> master

复制

虚拟机服务端

[root@master test-repo.git]# git log
commit ec56e9ee09edd5b4ab9ea5fe46927e91d4e09fd5 (HEAD -> master)
Author: 2392863668 <2392863668@qq.com>
Date:   Tue Sep 15 23:21:26 2020 +0800

    second commit

commit a1e4f83292ac8d9128c94a402ce2ada752fb14aa
Author: 2392863668 <2392863668@qq.com>
Date:   Tue Sep 15 23:16:34 2020 +0800

    first commit :)

复制

从服务端克隆仓库

我们甚至还可以从服务端克隆仓库下来:

Administrator@PC-20200713AJJH MINGW64 ~/Desktop
$ git clone ssh://root@192.168.128.139/root/git/test-repo.git
Cloning into 'test-repo'...
root@192.168.128.139's password:
remote: Counting objects: 6, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 6 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (6/6), done.

Administrator@PC-20200713AJJH MINGW64 ~/Desktop
$ cd test-repo/

Administrator@PC-20200713AJJH MINGW64 ~/Desktop/test-repo (master)
$ git log
commit ec56e9ee09edd5b4ab9ea5fe46927e91d4e09fd5 (HEAD -> master, origin/master, origin/HEAD)
Author: 2392863668 <2392863668@qq.com>
Date:   Tue Sep 15 23:21:26 2020 +0800

    second commit

commit a1e4f83292ac8d9128c94a402ce2ada752fb14aa
Author: 2392863668 <2392863668@qq.com>
Date:   Tue Sep 15 23:16:34 2020 +0800

    first commit :)

Administrator@PC-20200713AJJH MINGW64 ~/Desktop/test-repo (master)
$

复制

SSH 免密登录

如果你不想每次远程操作都输入密码的话,就略微看一下这一节吧!免密登录已经不是什么稀奇事儿了,我们稍微过一下!

先用 ssh-keygen -t rsa 命令在本地机客户端生成密钥:

把 id_rsa.pub 上传到虚拟机,并将 id_rsa.pub 内容追加(这儿的 >> 表示追加的意思,不然很可能就把文件里边原有的东西给覆盖掉了)到 authorized_keys 里边去:

[root@master ~]# pwd
/root
[root@master ~]# cat id_rsa.pub >> .ssh/authorized_keys

复制

然后?然后就没了!这个时候你在本地机客户端再次克隆的时候,就不需要输入虚拟机服务端的密码了。(这个操作使用 ssh-copy-id 来弄也行的)

Administrator@PC-20200713AJJH MINGW64 ~/Desktop
$ git clone ssh://root@192.168.128.139/root/git/test-repo.git
Cloning into 'test-repo'...
remote: Counting objects: 6, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 6 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (6/6), done.

复制

后记

细心的你可能会发现,服务端目录结构一直是这样的:

[root@master test-repo.git]# ll
total 16
drwxrwsr-x.  2 root root    6 Sep 15 22:56 branches
-rwxrwsr-x.  1 root root   66 Sep 15 22:56 config
-rwxrwsr-x.  1 root root   73 Sep 15 22:56 description
-rwxrwsr-x.  1 root root   23 Sep 15 22:56 HEAD
drwxrwsr-x.  2 root root 4096 Sep 15 22:56 hooks
drwxrwsr-x.  2 root root   21 Sep 15 22:56 info
drwxrwsr-x. 10 root root   90 Sep 15 23:21 objects
drwxrwsr-x.  4 root root   31 Sep 15 22:56 refs

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/526422.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Java 中 ArrayList 和 LinkedList 有什么区别

在Java中&#xff0c;ArrayList和LinkedList是两种常见的集合类。它们都实现了List接口&#xff0c;提供了类似数组的功能&#xff0c;可以存储任意类型的对象。虽然它们都可以实现相同的功能&#xff0c;但是它们的底层实现方式有所不同&#xff0c;因此在性能和用途上也存在一…

dom4j解析XML文件

主要为了讲解Mybatis中如何用dom4j解析XML,这里当作dom4j解析.XML文件的练习 引入mybatis配置文件和一个.xml文件 都是.xml <?xml version"1.0" encoding"UTF-8" ?> <!DOCTYPE configurationPUBLIC "-//mybatis.org//DTD Config 3.0//EN…

【C++】| 04——STL | 容器_vector

系列文章目录 【C】| 01——泛型编程 | 模板 【C】| 02——STL | 初识 【C】| 03——STL | 迭代器 【C】| 04——STL | 容器_vector 文章目录 1. vector容器2. vector库2.1 迭代器相关函数2.1 ww 1. vector容器 vector 与 动态数组 相似&#xff0c;可以自动调节自身大小。元素…

基于SpringBoot的美容院管理系统

末尾获取源码 开发语言&#xff1a;Java Java开发工具&#xff1a;JDK1.8 后端框架&#xff1a;SpringBoot 前端&#xff1a;Vue 数据库&#xff1a;MySQL5.7和Navicat管理工具结合 开发软件&#xff1a;IDEA / Eclipse 是否Maven项目&#xff1a;是 目录 一、项目简介 二、系…

Windows10中英文切换按钮消失?一招解决

目录 问题场景&#xff1a; 问题描述 原因分析&#xff1a; 解决方案&#xff1a; 1. 打开设置&#xff0c;选择时间和语言 2. 进入日期时间设置 3. 进入高级键盘设置 4. 勾选这个勾选框&#xff0c;问题解决 问题场景&#xff1a; 博主玩道德与法治V在线模式时&#…

BGP防环,路由反射器,BGP联盟

数据的出口是路由的入口 ospf内部&#xff1a;10 ospf外部&#xff1a;150 静态路由&#xff1a;60 RIP&#xff1a;100 BGP&#xff1a;255 当下一跳是0.0.0.0 表示的是自己 display bgp peer //查看bgp邻居表 display bgp routing-table //查看bgp数据库 display i…

WPF MaterialDesign 初学项目实战(3)动态侧边栏

其他文章 WPF MaterialDesign 初学项目实战&#xff08;0&#xff09;:github 项目Demo运行 WPF MaterialDesign 初学项目实战&#xff08;1&#xff09;首页搭建 WPF MaterialDesign 初学项目实战&#xff08;2&#xff09;首页导航栏样式 创建侧边栏实体类 新建MenuBar文件…

Python动物图像分割API简单调用实例演示,阿里达摩院视觉智能开放平台使用步骤

阿里云视觉智能开放平台 - 动物分割 效果图演示平台入口创建获取密钥本地图片转 URL 与密钥测试代码调用演示语义分割知识拓展阿里云达摩院智能视觉开放平台 效果图演示 调用本地图片处理后可以直接保存到本地&#xff0c;右边就是分割好的效果图&#xff0c;可以看到分割的效…

基于卷积的图像分类识别(五):ResNet ResNeXt

系列文章目录 本专栏介绍基于深度学习进行图像识别的经典和前沿模型&#xff0c;将持续更新&#xff0c;包括不仅限于&#xff1a;AlexNet&#xff0c; ZFNet&#xff0c;VGG&#xff0c;GoogLeNet&#xff0c;ResNet&#xff0c;DenseNet&#xff0c;SENet&#xff0c;MobileN…

C语言实现扫雷

总有一天你要一个人在暗夜中&#xff0c;向那座桥走过去 目录 一、文件及其对应代码 1.test.c 2.game.c 3.game.h 二、数组创建解析 1.创建两个数组的原因 2.预设数组较大的原因 三、计算周围雷的个数 四、向外扩展并延伸判断 扫雷游戏&#xff0c;相信大家都玩过&am…

【c++】图解类和对象(上)

类和对象&#xff08;上&#xff09; 文章目录 类和对象&#xff08;上&#xff09;一、面向过程和面向对象初步认识二、类的引入三、类的定义四、类的访问限定符及封装1.访问限定符2.封装 五、类的作用域六、类的实例化七、类对象模型八、this指针总结 一、面向过程和面向对象…

Mysql中select语句的执行流程?

Mysql中select语句的执行流程&#xff1f; 答&#xff1a; SELECT 语句的执行过程为&#xff1a;连接、查询缓存、a词法分析&#xff0c;语法分析&#xff0c;语义分析&#xff0c;构造执行树&#xff0c;生成执行计划、执行器执行计划&#xff0c;下面开始梳理一次完整的查询…

【MySQL】视图,事务、隔离级别

视图--虚表&#xff0c;不在数据库中存放数据&#xff0c;数据源于基本表。 为什么要使用视图 简化复杂的sql操作&#xff0c;在编写查询后&#xff0c;可以方便的重用它而不必知道它的查询细节。重复使用该sql语句。使用表的组成部分而不是整个表。保护数据&#xff0c;可以给…

vscode编译的时候:未定义标识符 thread

vscode编译的时候&#xff1a;未定义标识符 thread thread’ was not declared in this scope" 未定义标识符 thread 原因 MinGW GCC当前仍缺少标准C 11线程类的实现。 对于跨平台线程实现&#xff0c;GCC标准库依赖于gthreads / pthreads库。如果该库不可用&#xf…

手搓GPT系列之 - 通过理解LSTM的反向传播过程,理解LSTM解决梯度消失的原理 - 逐条解释LSTM创始论文全部推导公式,配超多图帮助理解(上篇)

1. 前言 说起RNN和LSTM&#xff0c;就绕不过Sepp Hochreiter 1997年的开山大作 Long Short-term Memory。奈何这篇文章写的实在是太劝退&#xff0c;整篇论文就2张图&#xff0c;网上很多介绍LSTM的文章都对这个模型反向传播的部分避重就轻&#xff0c;更少见&#xff08;反正…

2023/5/14学习总结

这道题我们可以看到数据范围很小 &#xff0c;所以可以使用暴力枚举&#xff0c;将所有可以组成长方形的长宽全遍历一遍&#xff0c;同时要满足这个长方形里没有障碍物的条件&#xff0c;取得周长最大值 #include<bits/stdc.h> using namespace std; typedef long long …

JavaSE基础(六)—— 面向对象、封装、对象内存图、成员变量和局部变量区别

目录 一、面向对象对象介绍 1. 面向对象的重点学习什么 二、设计对象并使用 1. 设计类&#xff0c;创建对象并使用 1.1 如何得到对象 1.2 如何使用对象 2. 定义类的几个补充注意事项 2.1 对象的成员变量的默认值规则 三、对象内存图 1. 多个对象内存图 2. 两个变量指…

Springboot +Flowable,流程表单应用之静态表单

一.简介 整体上来说&#xff0c;我们可以将Flowable 的表单分为三种不同的类型&#xff1a; 动态表单 这种表单定义方式我们可以配置表单中每一个字段的可读性、可写性、是否必填等信息&#xff0c;不过不能定义完整的表单页面。外置表单 外置表单我们只需要定义一下表单的 k…

生命周期、数据共享、ref引用、购物车案例

生命周期&数据共享 1.组件的生命周期2.组件之间的数据共享3.ref 引用4.购物车案例 1.组件的生命周期 生命周期 & 生命周期函数 生命周期&#xff08;Life Cycle&#xff09;是指一个组件从创建 -> 运行 -> 销毁的整个阶段&#xff0c;强调的是一个时间段。 生命…

chatGPT提问,BGP内容

ChatGPT提问&#xff1a;提问框架 背景角色任务要求 动态路由&#xff1a;内部网关协议&#xff1a;如RIP ISIS OSPF 在同一个公司内部运行的路由协议 外部网关协议&#xff1a;如 BGP 在不同公司之间运行的路由协议 AS&#xff1a;自治系统 每个自治系统都有唯一的…