Linux_Git 服务器安装笔记

环境:Vmware Workstation 10,CentOS-7-x86_64-DVD-1511.iso,Xshell 4.0,ip:192.168.216.140.

[[email protected] ~]# git

-bash: git: 未找到命令

[[email protected] ~]# yum install git

已加载插件:fastestmirror
。。。。
已安装:
git.x86_64 0:1.8.3.1-12.el7_4

作为依赖被安装:
libgnome-keyring.x86_64 0:3.12.0-1.el7 perl-Error.noarch 1:0.17020-2.el7 perl-Git.noarch 0:1.8.3.1-12.el7_4
perl-TermReadKey.x86_64 0:2.30-20.el7 rsync.x86_64 0:3.0.9-18.el7
完毕!

[[email protected] home]# id git

id: git: no such user

[[email protected] home]# useradd git

[[email protected] home]# passwd git

更改用户 git 的密码 。
新的 密码:
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。

[[email protected] ~]# git init - -bare /data/git/test.git

初始化空的 Git 版本库于 /data/git/test.git/

查看仓库所有者

[[email protected] ~]# ll /data/git/

总用量 4
drwxr-xr-x. 7 root root 4096 11月 30 17:12 test.git

[[email protected] ~]# ll /data/git/test.git/

总用量 16
drwxr-xr-x. 2 root root 6 11月 30 17:12 branches
-rw-r–r–. 1 root root 66 11月 30 17:12 config
-rw-r–r–. 1 root root 73 11月 30 17:12 description
-rw-r–r–. 1 root root 23 11月 30 17:12 HEAD
drwxr-xr-x. 2 root root 4096 11月 30 17:12 hooks
drwxr-xr-x. 2 root root 20 11月 30 17:12 info
drwxr-xr-x. 4 root root 28 11月 30 17:12 objects
drwxr-xr-x. 4 root root 29 11月 30 17:12 refs

更换仓库所有者

[[email protected] ~]# chown -R git:git /data/git/

[[email protected] ~]# ll /data/git/

总用量 4
drwxr-xr-x. 7 git git 4096 11月 30 17:12 test.git

[[email protected] ~]# ll /data/git/test.git/

总用量 16
drwxr-xr-x. 2 git git 6 11月 30 17:12 branches
-rw-r–r–. 1 git git 66 11月 30 17:12 config
-rw-r–r–. 1 git git 73 11月 30 17:12 description
-rw-r–r–. 1 git git 23 11月 30 17:12 HEAD
drwxr-xr-x. 2 git git 4096 11月 30 17:12 hooks
drwxr-xr-x. 2 git git 20 11月 30 17:12 info
drwxr-xr-x. 4 git git 28 11月 30 17:12 objects
drwxr-xr-x. 4 git git 29 11月 30 17:12 refs

[[email protected] ~]# vim /etc/ssh/sshd_config

RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys

在/home/git目录下创建 .ssh/authorized_keys文件

[[email protected] ~]# mkdir /home/git/.ssh && touch /home/git/.ssh/authorized_keys


本地使用cmd创建SSH 公钥和私钥

ssh-****** -t rsa -C “邮箱地址”

一路默认回车即可,完成后将C:\Users\liu.ssh\id_rsa.pub内容复制到git服务器/home/.ssh/authorized_keys文件中保存。


  • 在本地添加项目,并提交到远端master分支

git.exe push - -progress “origin” master:master

Linux_Git 服务器安装笔记
- 创建dev分支

Linux_Git 服务器安装笔记

  • 切换到dev分支

git.exe checkout dev - -

Linux_Git 服务器安装笔记
- 本地dev分支push到远端dev分支

git.exe push - -progress “origin” dev:dev

Linux_Git 服务器安装笔记

  • 本地所有分支

Linux_Git 服务器安装笔记

  • 远端所有分支

Linux_Git 服务器安装笔记

  • 分支合并,将dev分支合并到master分支

Linux_Git 服务器安装笔记

Linux_Git 服务器安装笔记

Linux_Git 服务器安装笔记

Linux_Git 服务器安装笔记

回去查看master分支

Linux_Git 服务器安装笔记


仓库迁移本地有一个名为git_demo的仓库

第一步,在服务器端创建一个新的仓库,命名为git_demo.git

[[email protected] ~]# git init - -bare /data/git/git_demo.git

[[email protected] ~]# chown -R git:git /data/git/git_demo.git

第二步,将本地git_demo上传到远端的地址修改为新的地址,让后上传即可

$ git push [email protected]:/data/git/git_demo.git master:master

Counting objects: 3, done.
Writing objects: 100% (3/3), 210 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To [email protected]:/data/git/git_demo.git
* [new branch] master -> master