ubuntu上搭建git服务器

红太狼 2021-03-17 15:58 784阅读 0赞

ubuntu上搭建git服务器

git服务器搭建

1.1安装git

1.2 创建git用户

  1. mrwuzs@mrwuz:~$ sudo adduser git
  2. [sudo] mrwuzs 的密码:
  3. 正在添加用户"git"...
  4. 正在添加新组"git" (1001)...
  5. 正在添加新用户"git" (1001) 到组"git"...
  6. 创建主目录"/home/git"...
  7. 正在从"/etc/skel"复制文件...
  8. 输入新的 UNIX 密码:
  9. 重新输入新的 UNIX 密码:
  10. passwd:已成功更新密码
  11. 正在改变 git 的用户信息
  12. 请输入新值,或直接敲回车键以使用默认值
  13. 全名 []:
  14. 房间号码 []:
  15. 工作电话 []:
  16. 家庭电话 []:
  17. 其它 []:
  18. 这些信息是否正确? [Y/n] y
  19. mrwuzs@mrwuz:~$

1.3创建仓库

我是在/home下创建的myreponsitory文件夹,在此文件夹下初始化一个空的MyProject.git文件夹改

  1. root@mrwuz:/home# ls
  2. git mrwuzs test_du
  3. root@mrwuz:/home# mkdir myreponsitory
  4. root@mrwuz:/home# cd myreponsitory/
  5. root@mrwuz:/home/myreponsitory# ls
  6. root@mrwuz:/home/myreponsitory# git init --bare MyProject.git
  7. 初始化空的 Git 仓库于 /home/myreponsitory/MyProject.git/
  8. root@mrwuz:/home/myreponsitory#

查看一下文档结构

  1. root@mrwuz:/home# tree -d
  2. .
  3. ├── git
  4. ├── mrwuzs
  5. │?? ├── 公共的
  6. │?? ├── 模板
  7. │?? ├── 视频
  8. │?? ├── 图片
  9. │?? ├── 文档
  10. │?? ├── 下载
  11. │?? ├── 音乐
  12. │?? └── 桌面
  13. ├── myreponsitory
  14. │?? └── MyProject.git
  15. │?? ├── branches
  16. │?? ├── hooks
  17. │?? ├── info
  18. │?? ├── objects
  19. │?? │?? ├── info
  20. │?? │?? └── pack
  21. │?? └── refs
  22. │?? ├── heads
  23. │?? └── tags
  24. └── test_du
  25. ├── test_du01
  26. ├── test_du02
  27. └── test_du03
  28. 25 directories
  29. root@mrwuz:/home#

1.4 更改MyProject.git的权限

  1. root@mrwuz:/home/myreponsitory# ls -la
  2. 总用量 12
  3. drwxr-xr-x 3 root root 4096 1 7 17:34 .
  4. drwxr-xr-x 6 root root 4096 1 7 17:33 ..
  5. drwxr-xr-x 7 root root 4096 1 7 17:34 MyProject.git
  6. root@mrwuz:/home/myreponsitory# chown -R git:git MyProject.git
  7. root@mrwuz:/home/myreponsitory# ls -la
  8. 总用量 12
  9. drwxr-xr-x 3 root root 4096 1 7 17:34 .
  10. drwxr-xr-x 6 root root 4096 1 7 17:33 ..
  11. drwxr-xr-x 7 git git 4096 1 7 17:34 MyProject.git
  12. root@mrwuz:/home/myreponsitory#

1.5 获取服务器的ip

2 客户端测试

2.1 windows测试1

在windows下安装好git,请自行搜索安装教程。

2.1.1 从服务器克隆仓库

  1. wzsfi@DESKTOP-DS5T4V5 MINGW64 ~
  2. $ git clone git@192.168.0.106:/home/myreponsitory/MyProject.git
  3. Cloning into 'MyProject'...
  4. The authenticity of host '192.168.0.106 (192.168.0.106)' can't be established.
  5. ECDSA key fingerprint is SHA256:SKYGgtFm1ogFTTwftDgipHF841sviOSqzXswW3p2LfI.
  6. Are you sure you want to continue connecting (yes/no)? yes
  7. Warning: Permanently added '192.168.0.106' (ECDSA) to the list of known hosts.
  8. git@192.168.0.106's password:
  9. warning: You appear to have cloned an empty repository.

2.2.2 往仓库推送内容

  1. wzsfi@DESKTOP-DS5T4V5 MINGW64 ~/MyProject (master)
  2. $ git add test.txt
  3. wzsfi@DESKTOP-DS5T4V5 MINGW64 ~/MyProject (master)
  4. $ git commit -m "tets"
  5. [master (root-commit) 2fbf0f8] tets
  6. 1 file changed, 0 insertions(+), 0 deletions(-)
  7. create mode 100644 test.txt
  8. wzsfi@DESKTOP-DS5T4V5 MINGW64 ~/MyProject (master)
  9. $ git push origin master
  10. git@192.168.0.106's password:
  11. Counting objects: 3, done.
  12. Writing objects: 100% (3/3), 201 bytes | 67.00 KiB/s, done.
  13. Total 3 (delta 0), reused 0 (delta 0)
  14. To 192.168.0.106:/home/myreponsitory/MyProject.git
  15. * [new branch] master -> master

发表评论

表情:
评论列表 (有 0 条评论,784人围观)

还没有评论,来说两句吧...

相关阅读