zoukankan      html  css  js  c++  java
  • 搭建本地git服务器

    最近因为项目需求,需要实现一个原型系统,加上后期项目需要多人协作,考虑采用了git做版本控制。

    这里主要简要描述下git服务器和客户端的搭建和配置。

    1、git服务器

    (1)安装git

    sudo apt-get install git

    git是一个分布式的版本控制工具,每个git仓库既可以作为服务器也可以作为客户端(不同于svn采用的集中式版本控制),故安装完成后需要配置用户信息

    git config --global user.name  "mal"
    git config --global user.email malt@gmial.com

    (2)添加git用户,避免项目和其他文件相互冲突

    adduser git
    passwd git

    (3)使用git用于新建一个仓库

    git@malt:~$ mkdir res.git
    git@malt:~$ cd res.git/
    git@malt:~/res.git$ git --bare init

     

    这里创建res.git仓库是使用git用户创建的,如果是root用户创建,后续采用 git remote add origin git@127.0.0.1:/home/git/res.git,对应权限错误。

    2、git客户端

    在git服务器远程仓库建立好后,就可以在客户端将自己的仓库加入到远程仓库中了。

    whthomas@whthomas:~/workplace/gitu$ git init
    初始化空的 Git 版本库于 /home/whthomas/workplace/gitu/.git/
    whthomas@whthomas:~/workplace/gitu$ touch README
    whthomas@whthomas:~/workplace/gitu$ echo hello >> README 
    whthomas@whthomas:~/workplace/gitu$ cat README 
    hello
    whthomas@whthomas:~/workplace/gitu$ git add .
    whthomas@whthomas:~/workplace/gitu$ git commit -m "add a README"
    [master (根提交) 59d4695] add a README
     1 file changed, 1 insertion(+)
     create mode 100644 README
    whthomas@whthomas:~/workplace/gitu$ git remote add origin git@127.0.0.1:/home/git/res.git
    whthomas@whthomas:~/workplace/gitu$ git push origin master 
    Counting objects: 3, done.
    Writing objects: 100% (3/3), 216 bytes | 0 bytes/s, done.
    Total 3 (delta 0), reused 0 (delta 0)
    To git@127.0.0.1:/home/git/res.git
     * [new branch]      master -> master

    同样的,也可以在其他目录下git clone远程仓库

    git clone git@localhost:/home/git/res.git

    3、设置免密码push

    在git服务器的git用户目录下。新建目录和文件(如果存在则不需要新建)

    $ cd /home/git  
    $ mkdir .ssh  
    $ chmod 700 .ssh  
    $ touch .ssh/authorized_keys  
    $ chmod 600 .ssh/authorized_keys 

    在git客户端中,查看ssh公私钥,如果没有,使用命令"ssh-keygen"可以创建

    其中id_rsa.pub为公钥,将其内容复制并追加到git服务器的authorized_keys中。之后则可以免密连接远程仓库。

  • 相关阅读:
    English,The Da Vinci Code, Chapter 23
    python,meatobject
    English,The Da Vinci Code, Chapter 22
    English,The Da Vinci Code, Chapter 21
    English,The Da Vinci Code, Chapter 20
    English,The Da Vinci Code, Chapter 19
    python,xml,ELement Tree
    English,The Da Vinci Code, Chapter 18
    English,The Da Vinci Code, Chapter 17
    English,The Da Vinci Code, Chapter 16
  • 原文地址:https://www.cnblogs.com/scu-cjx/p/9117435.html
Copyright © 2011-2022 走看看