zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    chrome 浏览器与chromedriver 对应关系以及 对应的驱动下载
    pip 安装six 报错 ModuleNotFoundError: No module named 'pip._internal.cli.main'
    django 连接远程mysql 报错 django.db.utils.OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: NO)")
    MySQL8.0允许外部访问
    Linux 安装mysql
    php导出导入excel插件
    解决php导出csv文件utf8中文乱码问题
    Docker 安装mysql5.6
    centos7 设置静态IP
    U盘制作centos7系统并安装
  • 原文地址:https://www.cnblogs.com/cyleon/p/11858658.html
Copyright © 2011-2022 走看看