搭建自己的Git仓库

面向过程的说说吧

所谓工欲善其事必先利其器,服务器上首先要先安装Git才可以部署Git服务端,我的服务器是Ubuntu系统,所以我就用ubuntu说事

1
apt install git

安装完成后检查一下git的版本

1
2
3
root@minloha:~# git --version
git version 2.25.1
root@minloha:~#

首先我们要创建公共用户git并输入密码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
root@minloha:~# id git
id: ‘git’: no such user
root@minloha:~# adduser git
Adding user `git' ...
Adding new group `git' (1000) ...
Adding new user `git' (1000) with group `git' ...
Creating home directory `/home/git' ...
Copying files from `/etc/skel' ...
New password:
Retype new password:
passwd: password updated successfully
Changing the user information for git
Enter the new value, or press ENTER for the default
Full Name []: iMinloha
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n]
root@minloha:~#

然后我们随便新建一个文件夹作为我们的git存放的地方

1
2
3
4
5
6
7
8
root@minloha:~/home# cd git
root@minloha:~/home/git# git init --bare MinProject.git
Initialized empty Git repository in /root/git/MinProject.git/
root@minloha:~/home/git# ls
MinProject.git
root@minloha:/home/git# chown -R git:git MinProject.git
chown: invalid user: ‘git:git’
root@minloha:/home/git#

然后仓库就创建好了,对你没看错,创建好了,接着就是那客户端去生成一下咯,我们就把Cmake的代码同步一下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# 先克隆服务端的git,记得修改ip
C:\Users\Minloha\Desktop\demo>git clone git@你的IP:/home/git/MinProject.git
Cloning into 'MinProject'...
The authenticity of host 'XXX.XXX.XXX.XXX (XXX.XXX.XXX.XXX)' can't be established.
ECDSA key fingerprint is SHA256:wZ1TgMK+m4PnfJkXKeUSTRLqmkaPeXVMXye1ijRkZK0.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'XXX.XXX.XXX.XXX' (ECDSA) to the list of known hosts.
git@XXX.XXX.XXX.XXX's password:
warning: You appear to have cloned an empty repository.

# 切换文件指针
C:\Users\Minloha\Desktop\demo>cd MinProject
# 把文件夹所有内容加入git
C:\Users\Minloha\Desktop\demo>git add .
# 设置git同步目标
C:\Users\Minloha\Desktop\demo>git commit -m 'CMake代码'
...............................
# 推送代码
C:\Users\Minloha\Desktop\myGit\MinProject>git push -u origin master
Enumerating objects: 122, done.
Counting objects: 100% (122/122), done.
Delta compression using up to 8 threads
Compressing objects: 100% (116/116), done.
Writing objects: 100% (122/122), 52.85 KiB | 1.06 MiB/s, done.
Total 122 (delta 57), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (57/57), done.
To XXX.XXX.XXX.XXX:/home/git/MinProject.git
* [new branch] master -> master

C:\Users\Minloha\Desktop\myGit\MinProject>

然后你就已经把代码克隆到服务器上了


搭建自己的Git仓库
https://blog.minloha.cn/posts/19275149c4814c2022012711.html
作者
Minloha
发布于
2022年1月27日
更新于
2024年4月8日
许可协议