• 公司如何创建自己的git远程仓库


    本文是基于ssh搭建git私服的学习总结,下面将会介绍如何搭建属于自己的远程库

    在自己的服务器上安装git

    我的服务器是centos7

    yum install git
    
    • 1

    若是ubuntu或自己安装了apt安装管理工具 ,也可以使用apt-get install git 进行安装,当然,安装之前可以先升级,安装比较新版本的git.我好想没升级安装的是1.8

    [root@iZ2ze3ldkm1p7szyuskxiwZ mygit]# git --version
    git version 1.8.3.1
    
    • 1
    • 2

    创建专门的远程仓库

    其实本地库和远程库没有什么太大区别,只不过远程库存放了各个不同用户的本地库push的数据,通俗的说,也就是远程库保存了很多文件.用户push一个,远程库就存一个.存好了,那么下次用户就可以pul或fecth取东西了.下面就是具体在服务器创建远程库的具体过程:

    创建一个新用户(可有可无)

    为了方便管理,我们可以在linux服务器上创建一个新用户,就叫git.

     adduser git
    
    • 1

    给这个git设置密码

     passwd git
    
    • 1

    这个新用户信息保存在/etc/passwd文件里,我们查看后五行,如下,可以看到git账户信息在最一行.
    在这里插入图片描述
    他的家目录是/home/git, shell是/bin/bash,当然,出于安全考虑,创建的git用户应该不允许登录shell,可以通过编辑/etc/passwd文件完成.当然,创建用户的时候就可以使用-s参数指定禁用shell,或者使用usermod修改.我们先不修改.继续操作.

    初始化远程库

    进入git的家目录/home/git,创建一个仓库test-repo

    [root@iZ2ze3ldkm1p7szyuskxiwZ ~]# su git
    [git@iZ2ze3ldkm1p7szyuskxiwZ root]$ cd ~
    [git@iZ2ze3ldkm1p7szyuskxiwZ ~]$ pwd
    /home/git
    [git@iZ2ze3ldkm1p7szyuskxiwZ ~]$ ls #我已经创建好了,没有可以创建
    test-repo
    [git@iZ2ze3ldkm1p7szyuskxiwZ ~]$ cd test-repo/
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    初始化一个裸库,不需要.git目录

    git init --bare
    
    • 1

    当然如果你非要这个目录,也不是不可以.下面这张图说明了加上–bare参数与不加有什么变化
    在这里插入图片描述
    可以看到主要文件都差不多,但也有几个文件不一样.

    本地进行push

    git服务器就基本就搭建好了.现在本地就可以远程push了.远程库的地址git@182.92.200.149:/home/git/test-repo

    git push git@182.92.200.149:/home/git/test-repo master
    
    • 1

    输入git的密码,就可以push成功了

    在这里插入图片描述
    进入远程库确认,如下,可以看到多了一个分支,就是刚才push的

    [git@iZ2ze3ldkm1p7szyuskxiwZ test-repo]$ ls -a
    .  ..  branches  config  description  HEAD  hooks  info  objects  refs
    [git@iZ2ze3ldkm1p7szyuskxiwZ test-repo]$ git branch -v
    * master c964f4f tom开发了一个模块
    * 
    [git@iZ2ze3ldkm1p7szyuskxiwZ test-repo]$ 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    本地clone

    我们在本地新建一个空的test目录,如下
    在这里插入图片描述
    现在进行clone,就把刚才的克隆下来git clone git@182.92.200.149:/home/git/test-repo master

    root@xiaoxin-Inspiron-5567:/usr/local/gitrepo-tet/test# git clone git@182.92.200.149:/home/git/test-repo master
    Cloning into 'master'...
    The authenticity of host '182.92.200.149 (182.92.200.149)' can't be established.
    ECDSA key fingerprint is SHA256:hMZZ9soJQf5V4hhGe/ddcwdFnt91GErC5q/BxIuPxbw.
    Are you sure you want to continue connecting (yes/no)? yes
    Warning: Permanently added '182.92.200.149' (ECDSA) to the list of known hosts.
    git@182.92.200.149's password: 
    remote: Counting objects: 6, done.
    remote: Compressing objects: 100% (4/4), done.
    remote: Total 6 (delta 1), reused 0 (delta 0)
    Receiving objects: 100% (6/6), done.
    Resolving deltas: 100% (1/1), done.
    root@xiaoxin-Inspiron-5567:/usr/local/gitrepo-tet/test# ls -a
    .  ..  master
    root@xiaoxin-Inspiron-5567:/usr/local/gitrepo-tet/test# cd master/
    root@xiaoxin-Inspiron-5567:/usr/local/gitrepo-tet/test/master# ls -a
    .  ..  .git  test.md
    root@xiaoxin-Inspiron-5567:/usr/local/gitrepo-tet/test/master# 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18

    也没问题.

  • 相关阅读:
    ASP.NET配置文件Web.config 详细解释
    Firefox 3.6最新功能:网页可根据设备方位调整角度
    ascx + wrapper page + jQuery的Ajax解决方案
    C#中常用的文件操作方法
    Excel鲜为人知的35招秘技
    NHibernate.Search 基于Lucene.NET的全文索引
    Firefox和IE之间7个JavaScript的差异
    .net2.0使用json的知识,要点,问题和解决方案
    服务器响应HTTP的类型ContentType大全
    欢迎Clonezilla,再见Symantec Ghost
  • 原文地址:https://www.cnblogs.com/YuyuanNo1/p/13878145.html
Copyright © 2020-2023  润新知