zoukankan      html  css  js  c++  java
  • 4. 服务器上的Git

    4.1 搭建Git服务器 git1

    ]# git config --global user.name "user1"
    ]# git config --global user.email user1@example.com
    ]# groupadd git
    ]# useradd git -g git
    ]# su - git
    ~]$ mkdir .ssh && chmod 700 .ssh
    ~]$ touch .ssh/authorized_keys && chmod 600 .ssh/authorized_keys
    ~]$ mkdir git1.git
    # 创建裸仓库
    git1.git]$ git init --bare
     
    4.2 配置其他服务器免密登录 git2
    ]# git config --global user.name "user2"
    ]# git config --global user.email user2@example.com
    ]# groupadd git
    ]# useradd git -g git
    ]# su - git
    ~]$ mkdir .ssh && chmod 700 .ssh
    .ssh]$ ssh-keygen
    .ssh]$ ls
    authorized_keys  id_rsa  id_rsa.pub
    # 将 id_rsa.pub 文件内容添加到 git1 的 authorized_keys 里即可
    .ssh]$ ssh-copy-id git@47.105.86.193 git1的IP
    git2 以 root身份配置 /etc/hosts
    git2 ~]# cat /etc/hosts  0.55 为 git1的IP
    ...
    192.168.0.55    gitserver
     
    4.3 git2 推送本地代码到裸仓库
    git2-proj]$ git init
    git2-proj]$ git commit -m 'Add git2.txt at VM git2'
    git2-proj]$ git remote add origin git@gitserver:/home/git/git1.git
    git2-proj]$ git push origin master  # 推送到 git1 服务器
     
    4.4 其他服务器分工协作 git2 模拟其他服务器
    git2-proj]$ git rm git2.txt
    git2-proj]$ git commit -m 'del git2.txt at VM git2'
    # 测试本地仓库为空 克隆远程仓库代码 git2 之前提交的代码
    git2-proj]$ git clone git@gitserver:/home/git/git1.git
    # 查看
    git2-proj]$ ls  # 克隆回来的目录叫 git1
    git1
    git2-proj]$ cd git1/
    git2 git1]$ ls  # 之前 git2 的仓库代码
    git2.txt
    # 修改并推送
    git1]$ git commit -am 'Modify git2.txt At Other VM'
    git2 git1]$ git push origin master
     
    # 此时其他服务器再执行 git clone git@gitserver:/home/git/git1.git 时,代码已经时更新过的
    git2 git1]$ git log
    commit 8d9443989651739ca6267bc5980ecd6d17646110 (HEAD -> master, origin/master, origin/HEAD)
    Author: user2 <user2@example.com>
    Date:   Fri Aug 14 16:49:57 2020 +0800
     
        Modify git2.txt At Other VM
     
    commit 2b5c820871528b35565436712937c9177c0241cc
    Author: user2 <user2@example.com>
    Date:   Fri Aug 14 16:24:57 2020 +0800
     
        Add git2.txt at VM git2
  • 相关阅读:
    nginx超时问题
    linux打包文件,压缩文件
    centos查看文件夹大小
    Nginx反向代理和负载均衡
    nginx的location配置详解
    nginx错误Upstream timed out
    mysql处理函数
    SQL左右连接中的on and和on where的区别
    html select change事件触发
    get,post区别
  • 原文地址:https://www.cnblogs.com/luwei0915/p/13819270.html
Copyright © 2011-2022 走看看