ubuntu上搭建git服务器
git服务器搭建
1.1安装git
1.2 创建git用户
mrwuzs@mrwuz:~$ sudo adduser git
[sudo] mrwuzs 的密码:
正在添加用户"git"...
正在添加新组"git" (1001)...
正在添加新用户"git" (1001) 到组"git"...
创建主目录"/home/git"...
正在从"/etc/skel"复制文件...
输入新的 UNIX 密码:
重新输入新的 UNIX 密码:
passwd:已成功更新密码
正在改变 git 的用户信息
请输入新值,或直接敲回车键以使用默认值
全名 []:
房间号码 []:
工作电话 []:
家庭电话 []:
其它 []:
这些信息是否正确? [Y/n] y
mrwuzs@mrwuz:~$
1.3创建仓库
我是在/home下创建的myreponsitory文件夹,在此文件夹下初始化一个空的MyProject.git文件夹改
root@mrwuz:/home# ls
git mrwuzs test_du
root@mrwuz:/home# mkdir myreponsitory
root@mrwuz:/home# cd myreponsitory/
root@mrwuz:/home/myreponsitory# ls
root@mrwuz:/home/myreponsitory# git init --bare MyProject.git
初始化空的 Git 仓库于 /home/myreponsitory/MyProject.git/
root@mrwuz:/home/myreponsitory#
查看一下文档结构
root@mrwuz:/home# tree -d
.
├── git
├── mrwuzs
│?? ├── 公共的
│?? ├── 模板
│?? ├── 视频
│?? ├── 图片
│?? ├── 文档
│?? ├── 下载
│?? ├── 音乐
│?? └── 桌面
├── myreponsitory
│?? └── MyProject.git
│?? ├── branches
│?? ├── hooks
│?? ├── info
│?? ├── objects
│?? │?? ├── info
│?? │?? └── pack
│?? └── refs
│?? ├── heads
│?? └── tags
└── test_du
├── test_du01
├── test_du02
└── test_du03
25 directories
root@mrwuz:/home#
1.4 更改MyProject.git的权限
root@mrwuz:/home/myreponsitory# ls -la
总用量 12
drwxr-xr-x 3 root root 4096 1月 7 17:34 .
drwxr-xr-x 6 root root 4096 1月 7 17:33 ..
drwxr-xr-x 7 root root 4096 1月 7 17:34 MyProject.git
root@mrwuz:/home/myreponsitory# chown -R git:git MyProject.git
root@mrwuz:/home/myreponsitory# ls -la
总用量 12
drwxr-xr-x 3 root root 4096 1月 7 17:34 .
drwxr-xr-x 6 root root 4096 1月 7 17:33 ..
drwxr-xr-x 7 git git 4096 1月 7 17:34 MyProject.git
root@mrwuz:/home/myreponsitory#
1.5 获取服务器的ip
2 客户端测试
2.1 windows测试1
在windows下安装好git,请自行搜索安装教程。
2.1.1 从服务器克隆仓库
wzsfi@DESKTOP-DS5T4V5 MINGW64 ~
$ git clone git@192.168.0.106:/home/myreponsitory/MyProject.git
Cloning into 'MyProject'...
The authenticity of host '192.168.0.106 (192.168.0.106)' can't be established.
ECDSA key fingerprint is SHA256:SKYGgtFm1ogFTTwftDgipHF841sviOSqzXswW3p2LfI.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.0.106' (ECDSA) to the list of known hosts.
git@192.168.0.106's password:
warning: You appear to have cloned an empty repository.
2.2.2 往仓库推送内容
wzsfi@DESKTOP-DS5T4V5 MINGW64 ~/MyProject (master)
$ git add test.txt
wzsfi@DESKTOP-DS5T4V5 MINGW64 ~/MyProject (master)
$ git commit -m "tets"
[master (root-commit) 2fbf0f8] tets
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 test.txt
wzsfi@DESKTOP-DS5T4V5 MINGW64 ~/MyProject (master)
$ git push origin master
git@192.168.0.106's password:
Counting objects: 3, done.
Writing objects: 100% (3/3), 201 bytes | 67.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To 192.168.0.106:/home/myreponsitory/MyProject.git
* [new branch] master -> master