• 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
  • 相关阅读:
    了解教育网访问情况
    .NET开源社区存在的问题
    欢迎大家谈谈Windows Live Mail desktop的使用感受
    [公告]新版排行榜页面发布
    国外技术新闻[来自Digg.com]
    首页小改进
    [SQL Server 2005]String or binary data would be truncated
    Linux获得真正3D桌面 开源支持者喜不自禁
    新版 .net开发必备10大工具
    使用新类型Nullable处理数据库表中null字段
  • 原文地址:https://www.cnblogs.com/cyleon/p/11858658.html
Copyright © 2020-2023  润新知