Git 创建操作
在本章中,我们将看到如何创建一个远程Git仓库,从现在开始,我们将会把它作为Git服务器。我们需要一个的Git服务器允许团队协作。
创建新用户
# add new group
[root@CentOS ~]# groupadd dev # add new user
[root@CentOS ~]# useradd -G devs -d /home/gituser -m -s /bin/bash gituser
# change password
[root@CentOS ~]# passwd gituser
上面的命令会产生以下结果。
Changing password for user gituser. New password: Retype new password: passwd: all authentication tokens updated successfully.
创建一个裸库
让我们初始化一个新的资料库使用init命令后面加上 -bare选项。它初始化没有工作目录库。按照惯例裸库必须命名为 .git。
[gituser@CentOS ~]$ pwd /home/gituser
[gituser@CentOS ~]$ mkdir project.git
[gituser@CentOS ~]$ cd project.git/
[gituser@CentOS project.git]$ ls
[gituser@CentOS project.git]$ git –bare init Initialized empty Git repository in /home/gituser-m/project.git/
[gituser@CentOS project.git]$ ls branches config description HEAD hooks info objects refs
生成公共/私有RSA密钥对
让我们遍历Git服务器端的配置过程中,使用ssh-keygen实用程序生成公共/私有RSA密钥对,我们将使用这些键进行用户认证。
打开一个终端并输入以下命令,直接按回车为每个输入。成功完成后,它会创建主目录 .ssh目录内。
tom@CentOS ~]$ pwd /home/tom [tom@CentOS ~]$ ssh-keygen
上面的命令会产生以下结果。
Generating public/private rsa key pair. Enter file in which to save the key (/home/tom/.ssh/id_rsa): Press Enter Only Created directory ‘/home/tom/.ssh’. Enter passphrase (empty for no passphrase): —————> Press Enter Only Enter same passphrase again: ——————————> Press Enter Only Your identification has been saved in /home/tom/.ssh/id_rsa. Your public key has been saved in /home/tom/.ssh/id_rsa.pub. The key fingerprint is: df:93:8c:a1:b8:b7:67:69:3a:1f:65:e8:0e:e9:25:a1 tom@CentOS The key’s randomart image is: +–[ RSA 2048]—-+ | | | | | | | . | | Soo | | o*B. | | E = *.= | | oo==. . | | ..+Oo | +—————–+
ssh-keygen 已经产生了两个键,第一个是私有的(即id_rsa),另一个是公共(即id_rsa.pub文件)。
注: 切勿与他人共享你的私钥。
添加键 authorized_keys
假设有两个开发项目即Tom 和Jerry工作。两个用户生成公钥。让我们来看看如何使用这些密钥进行身份验证。
Tom 添加他的公钥服务器使用 ssh-copy-id这个命令下面给出
[tom@CentOS ~]$ pwd /home/tom
[tom@CentOS ~]$ ssh-copy-id -i ~/.ssh/id_rsa.pub gituser@git.server.com
上面的命令会产生以下结果。
gituser@git.server.com’s password: Now try logging into the machine, with “ssh ‘gituser@git.server.com'”, and check in: .ssh/authorized_keys to make sure we haven’t added extra keys that you weren’t expecting.
同样,Jerry 也增加了他的公共密钥服务器使用 ssh-copy-id 这个命令。
[jerry@CentOS ~]$ pwd /home/jerry
[jerry@CentOS ~]$ ssh-copy-id -i ~/.ssh/id_rsa gituser@git.server.com
上面的命令会产生以下结果。
gituser@git.server.com’s password: Now try logging into the machine, with “ssh ‘gituser@git.server.com'”, and check in: .ssh/authorized_keys to make sure we haven’t added extra keys that you weren’t expecting.
推修改到版本库
我们已经创建了裸库在服务器上,并允许两个用户访问。从现在Tom 和 Jerry 可以把他们修改到版本库,将其添加为远程。
Git的init命令创建 .git 目录来存储元数据的存储库。每次读取配置从 .git/config 文件.
Tom 创建一个新的目录,添加READE文件作为初始提交并提交他的变化。提交后,他确认提交信息,运行git日志命令。
[tom@CentOS ~]$ pwd /home/tom
[tom@CentOS ~]$ mkdir tom_repo
[tom@CentOS ~]$ cd tom_repo/
[tom@CentOS tom_repo]$ git init Initialized empty Git repository in /home/tom/tom_repo/.git/
[tom@CentOS tom_repo]$ echo ‘TODO: Add contents for README’ > README
[tom@CentOS tom_repo]$ git status -s ?? README
[tom@CentOS tom_repo]$ git add .
[tom@CentOS tom_repo]$ git status -s A README
[tom@CentOS tom_repo]$ git commit -m ‘Initial commit’
上面的命令会产生以下结果。
[master (root-commit) 19ae206] Initial commit 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 README
Tom 执行git 的日志命令,检查日志消息。
[tom@CentOS tom_repo]$ git log
上面的命令会产生以下结果。
commit 19ae20683fc460db7d127cf201a1429523b0e319 Author: Tom Cat <tom@yiibai.com> Date: Wed Sep 11 07:32:56 2013 +0530 Initial commit
Tom 提交了他的变化到本地资源库。现在是时候将更改到远程仓库。但在此之前,我们必须添加作为远程仓库,这是一个时间的操作。在此之后,他可以放心地推送到远程存储库的更改。
注: 默认情况下,Git的推到匹配的分支:对于每一个分支退出本地端的远程端更新,如果已经存在具有相同名称的一个分支。在我们的教程每次我推原点主分支的变化,根据您的要求,使用适当的分支名。
[tom@CentOS tom_repo]$ git remote add origin gituser@git.server.com:project.git
[tom@CentOS tom_repo]$ git push origin master
上面的命令会产生以下结果。
Counting objects: 3, done. Writing objects: 100% (3/3), 242 bytes, done. Total 3 (delta 0), reused 0 (delta 0) To gituser@git.server.com:project.git * [new branch] master −> master
现在更改成功提交到远程仓库。
PS:如果您想和业内技术大牛交流的话,请加qq群(521249302)或者关注微信公众 号(AskHarries),谢谢!
Git 创建操作的更多相关文章
- Git远程操作详解
Git是目前最流行的版本管理系统,学会Git几乎成了开发者的必备技能. Git有很多优势,其中之一就是远程操作非常简便.本文详细介绍5个Git命令,它们的概念和用法,理解了这些内容,你就会完全掌握Gi ...
- Git远程操作
Git远程操作 // */ // ]]> Git远程操作 Table of Contents 1 Git远程命令概览 2 Git远程仓库与本地仓库的关系图 3 git clone 4 git ...
- [转]Git远程操作详解
原文:http://www.ruanyifeng.com/blog/2014/06/git_remote.html Git是目前最流行的版本管理系统,学会Git几乎成了开发者的必备技能. Git有很多 ...
- Git 基础操作
[TOC] 在Linux上安装Git $ git --version #查看git的版本号 $ sudo apt-get install git # 安装git 创建版本库 $ git init # ...
- Git基础操作
配置秘钥 1.检查本机有没有秘钥 检查~/.ssh看看是否有名为d_rsa.pub和id_dsa.pub的2个文件. $ ~/.sshbash: /c/Users/lenovo/.ssh: Is a ...
- Git 远程操作详解
Git是目前最流行的版本管理系统,学会Git几乎成了开发者的必备技能. Git有很多优势,其中之一就是远程操作非常简便.本文详细介绍5个Git命令,它们的概念和用法,理解了这些内容,你就会完全掌握Gi ...
- git创建分支并提交项目
git 创建分支, 切换分支, 合并分支, 删除分支及提交[commit提交到本地仓库push名利提交到远程服务器], 检出[pull], 冲突修改, 本地仓库同步远程服务器[pul和push命令l] ...
- 【Git】Git远程操作详解
Git是目前最流行的版本管理系统,学会Git几乎成了开发者的必备技能. Git有很多优势,其中之一就是远程操作非常简便.本文详细介绍5个Git命令,它们的概念和用法,理解了这些内容,你就会完全掌握Gi ...
- Composer 结合 Git 创建 “服务类库”
Composer 结合 Git 创建 "服务类库" 我一直认为,现在的 PHP 已经进展到了工程化的领域.以前的 PHP 开发者,以快为美,速度和规模永远都是矛盾体.现在的 PHP ...
随机推荐
- Android开发中的神坑和知识点记录
1.SDK Manager.exe闪退的问题 http://blog.csdn.net/fambit025/article/details/26984345 1.找到android.bat,在源码处找 ...
- django -- 联合索引
一.定义: from django.db import models # Create your models here. class Person(models.Model): first_name ...
- 查询系统负载信息 Linux 命令详解
linux uptime命令主要用于获取主机运行时间和查询linux系统负载等信息.uptime命令过去只显示系统运行多久.现在,可以显示系统已经运行了多长 时间,信息显示依次为:现在时间.系统已经运 ...
- 抛弃百度UMEditor,拥抱summernote (解决上传文件又慢又卡的问题)
由于一些项目上的原因以及相关因素,我们使用其他富文本编辑器替代了UMEditor 本来用CKEditor,但是团队觉得使用起来很不顺手,尤其图片上传十分不爽,功能复杂但是使用起来比较麻烦 后来我们又替 ...
- IOS 启动画面和图标设置(适配IOS7 and Xcode5)
关于IOS程序设置启动画面以及图标的设备目前主要为:IPhone设备 和IPad设备 IPhone启动画面以及图标的设置 目前IPhone的分辨率为:320X480.640X960.640X1136. ...
- Vue知识点超快速学习
基础知识: vue的生命周期: beforeCreate/created.beforeMount/mounted.beforeUpdate/updated.beforeDestory/destorye ...
- 当update的查询条件是数组的时候,upsert会失效
不管是findOneAndUpdate还是update方法,只要他们的查询条件是数组,upsert就会失效,比如: //这段代码只会更新已存在的数据,不存在的不会插入 tagModel.update( ...
- mongoose的update函数中的回调函数是必须要传的吗
mongoose中的update的回调函数是必须要传的,如果不传,则不会更新. 例如这样写是不会更新的 tagModel.update({name:tagName},{$inc:{total:1}}, ...
- 【Cmd】那些年,我们迷恋的cmd命令(二)
那些年,我们迷恋的命令(一) 那些年,我们迷恋的命令(二) Linux系统下基本命令 Linux系统下基本命令: 要区分大小写 uname 显示版本信息(同win2K的 ver) dir 显示当前目录 ...
- JVM垃圾回收--年轻代、年老点和持久代
关键字约定 Young generation –>新生代 Tenured / Old Generation –>老年代 Perm Area –>永久代 年轻代: 所有新生成的对象首先 ...