• git仓库的安装和基本使用


    一、安装git软件

    # yum install git -y

    二、初始化git仓库

    2.1 在git仓库的机器进行配置

    # ifconfig eth0 | awk -F '[ :]+' 'NR==2 {print $3}'
     192.168.5.71

    # useradd git # 创建用户 #
    passwd git # 为git用户设置密码 # su - git # 切换用户 $ mkdir www.git $ cd www.git/ $ git --bare init # 初始化远程仓库 Initialized empty Git repository in /home/git/www.git/ $ ll -a total 16 drwxrwxr-x 7 git git 111 Nov 14 15:14 . drwx------ 3 git git 73 Nov 14 15:14 .. drwxrwxr-x 2 git git 6 Nov 14 15:14 branches -rw-rw-r-- 1 git git 66 Nov 14 15:14 config -rw-rw-r-- 1 git git 73 Nov 14 15:14 description -rw-rw-r-- 1 git git 23 Nov 14 15:14 HEAD drwxrwxr-x 2 git git 4096 Nov 14 15:14 hooks drwxrwxr-x 2 git git 20 Nov 14 15:14 info drwxrwxr-x 4 git git 28 Nov 14 15:14 objects drwxrwxr-x 4 git git 29 Nov 14 15:14 refs

    2.2 在远程机器中拉取代码(另一台机器操作)

    # ifconfig eth0 | awk -F '[ :]+' 'NR==2 {print $3}'
    192.168.5.72
    
    # mkdir test
    # cd test/
    # git clone git@192.168.5.71:/home/git/www.git           # 输入上面创建的git的用户密码
    Cloning into 'www'...
    git@192.168.5.71's password:
    warning: You appear to have cloned an empty repository.
    # ll
    -a www/.git/ total 16 drwxr-xr-x 7 root root 111 Nov 14 15:16 . drwxr-xr-x 3 root root 17 Nov 14 15:16 .. drwxr-xr-x 2 root root 6 Nov 14 15:16 branches -rw-r--r-- 1 root root 259 Nov 14 15:16 config -rw-r--r-- 1 root root 73 Nov 14 15:16 description -rw-r--r-- 1 root root 23 Nov 14 15:16 HEAD drwxr-xr-x 2 root root 4096 Nov 14 15:16 hooks drwxr-xr-x 2 root root 20 Nov 14 15:16 info drwxr-xr-x 4 root root 28 Nov 14 15:16 objects drwxr-xr-x 4 root root 29 Nov 14 15:16 refs

    三、免密钥拉取代码

    3.1 在远端要拉取代码的机器创建公钥,并将公钥放入git机器中

    # ssh-keygen -t rsa
    # ssh-copy-id -i /root/.ssh/id_rsa.pub git@192.168.5.71

    3.2 进行免密拉取代码

    # git clone git@192.168.5.71:/root/git/www.git
    Cloning into 'www'...
    warning: You appear to have cloned an empty repository.

    3.3 免密push代码文件

    # git clone git@192.168.5.71:/home/git/www.git
    Cloning into 'www'...
    warning: You appear to have cloned an empty repository.
    
    # cd www/
    # echo 'sleep' > index.html
    # git add .
    
    # git commit -m 'add index.html file'
    [master (root-commit) b629ad0] add index.html file
     1 file changed, 1 insertion(+)
     create mode 100644 index.html
    
    # git push origin master
    Counting objects: 3, done.
    Writing objects: 100% (3/3), 221 bytes | 0 bytes/s, done.
    Total 3 (delta 0), reused 0 (delta 0)
    To git@192.168.5.71:/home/git/www.git
     * [new branch]      master -> master
  • 相关阅读:
    [匈牙利] 洛谷 P2526 小狗散步
    [匈牙利] 洛谷 P1129 矩阵游戏
    [树形dp] Jzoj P5233 概率博弈
    [线段树] Jzoj P4231 寻找神格
    [状压dp][期望] 洛谷 P2473 奖励关
    [倍增][双向链表] Jzoj P3101 开车旅行
    [高精度][数学] Jzoj P3771 小Z的烦恼
    [并查集][排序] Jzoj P2940 生成输入数据
    [dfs][概率] Jzoj P2941 贿赂
    [权值线段树] Jzoj P4417 神奇的字符串
  • 原文地址:https://www.cnblogs.com/cyleon/p/11858658.html
Copyright © 2020-2023  润新知