前些日子因为某些原因,需要在windows上创建一个remote仓库。

由于实在是太麻烦而且时间紧急,就直接用了gitstack。

发现这个东西居然需要付费,未认证时只能创建两个用户。

其实对我而言足够了,但不是长久之计。

好在后来又有了一台机器装了linux,这就回到正轨。

因为我也是一直使用别人弄的remote仓库,这次便把创建过程记录下来。

git init是第一步,我经常很理所当然地进行如下操作:


[root@alvez-VM ~]# mkdir myProject
[root@alvez-VM ~]# cd myProject/
[root@alvez-VM myProject]# git init
Initialized empty Git repository in /root/myProject/.git/
[root@alvez-VM myProject]# touch myProject.md
[root@alvez-VM myProject]# echo "##myProject">>myProject.md
[root@alvez-VM myProject]# git add .
[root@alvez-VM myProject]# git commit -m"add md file"
[root@alvez-VM myProjet]# git remote add origin ssh://root@localhost/~/myProject/.git
[root@alvez-VM myProjet]# git remote -v
origin ssh://root@localhost/~/myProject/.git (fetch)
origin ssh://root@localhost/~/myProject/.git (push)

有一点需要注意,git init还是git init --bare,两者的区别是什么?

加了--bare的就是bare repository嘛 (╯‵□′)╯︵┻━┻

简单来说,bare仓库的意义在于在服务器集中管理,以管理多个开发者的提交。

即使没有加--bare,开发人员仍然可以对该工程进行clone,只不过向这个仓库push时会提示如下信息并失败:


remote: error: refusing to update checked out branch: refs/heads/master remote: error: By default, updating the current branch in a non-bare repository
remote: error: is denied, because it will make the index and work tree inconsistent
remote: error: with what you pushed, and will require 'git reset --hard' to match
remote: error: the work tree to HEAD.
remote: error:
remote: error: You can set 'receive.denyCurrentBranch' configuration variable to
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into
remote: error: its current branch; however, this is not recommended unless you
remote: error: arranged to update its work tree to match what you pushed in some
remote: error: other way.
remote: error:
remote: error: To squelch this message and still keep the default behaviour, set
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.

若只是在server中对本地进行push则没有问题,也就是说git init只是给自己一个人玩的。

git init后的目录下包括两样东西,.git和真实的工作目录,而bare仓库下仅仅是.git。

也就是说,上面第一步就错了,对于init,只要在目录下git init --bare就足够了,也不需要remote add。

这样就可以clone并push了


$ git clone root@serverip:myProject
Cloning into 'myProject'...
warning: You appear to have cloned an empty repository.
Checking connectivity... done
$ cd myProject/
$ touch pushTest.txt
$ echo "push test">pushTest.txt
$ git add .
warning: LF will be replaced by CRLF in pushTest.txt.
The file will have its original line endings in your working directory.
$ git commit -m"test file"
[master (root-commit) 05f0722] test file
warning: LF will be replaced by CRLF in pushTest.txt.
The file will have its original line endings in your working directory.
1 file changed, 1 insertion(+)
create mode 100644 pushTest.txt
$ git push
 

clone或者push时会提示输入密码,输入个密码也未尝不可,

几个开发者使用一个用户名密码也没什么,每个人一套各自的用户名密码就上几次userAdd也没什么意义。

不如让开发者生成key pair并把公钥给我管理。

可以通过以下命令生成(rsa或者dsa,或者看情况加入其他参数):


ssh-keygen -t rsa
 

执行后会在用户目录下的.ssh下生成相应密钥,将.pub文件发给管理员即可。

假设管理员拿到的文件名为id_rsa.test.pub并放在用户目录下,执行如下操作加入权限并确认:


[root@alvez-VM ~]# cat id_dsa.test.pub >> ~/.ssh/authorized_keys
[root@alvez-VM ~]# cd .ssh/
[root@alvez-VM .ssh]# cat authorized_keys
 

好了,以上就是远程库的创建与认证。

Git - 远程库的创建与认证的更多相关文章

  1. Git版本库的创建(Ubuntu)

    在Ubuntu上学习Git随笔. 一. git 仓库的安装 git 在终端用git命令查看Ubuntu是否安装git版本库,如果没有安装,最新版本(Ubuntu18.04)会提示用下面命令进行安装. ...

  2. git 远程库 创建私钥

    1.创建SSH Key.在用户主目录下,看看有没有.ssh目录,如果有,再看看这个目录下有没有id_rsa和id_rsa.pub这两个文件,如果已经有了,可直接跳到下一步.如果没有,打开Shell(W ...

  3. git 远程仓库 轻松创建

    很多时候,为了方面管理我们写的代码,我们采用git 远程仓库来进行管理和备份.防止代码被他人篡改或删除.那如何来进行创建远程仓库呢? 1.我们必须有一个远程服务器端,在这里可以把任意一台电脑作为服务器 ...

  4. git远程库代码版本回滚方法

    最近使用git时, 造成了远程库代码需要回滚到之前版本的情况,为了解决这个问题查看了很多资料. 问题产生原因: 提交了错误的版本到远程库. 以下是解决的方法, 供大家参考: 1.对本地代码库进行回滚 ...

  5. Git远程库

    要关联一个远程主机,使用命令 git remote add origin <url> : 删除远程主机,使用命令 git remote rm origin ; git push 的一般形式 ...

  6. 将本地项目上传到git远程库(初始化)

    准备条件: 首先,有一个远程仓库地址,本文中的地址为“http://git.xxxxxxxx.net.cn/jacun/imagegrap.git”; 第一步:在本地创建初始化仓库: git init ...

  7. git远程库GitHub

    首先,注册一个GitHub(github.com)帐号,免费获得Git远程仓库 由于本地Git仓库和GitHub仓库之间的传输是通过SSH加密的,所以,需要一点设置: 第1步:创建SSH Key.在用 ...

  8. Git远程库版本回滚

    在git的一般使用中,如果发现错误的将不想staging的文件add进入index之后,想回退取消,这就叫做git代码库回滚: 指的是将代码库某分支退回到以前的某个commit id.可以使用命令:g ...

  9. git 远程库和url

    我们使用 git remote add origin <url> 来关联远程主机,这个origin就是关联的远程主机名,如果我们想同时关联两个远程主机,我们可以用 git remote a ...

随机推荐

  1. Android 用 res 中文件名获取资源 id 的方法

    res 中我们可能会放很多图片和音频视频等.它们放在 R.drawable, R.raw 下面. 有一种情况是,比如我有一个数据库保存项目中声音的一些信息.声音的 id 就很难保存.因为我们不能把 R ...

  2. “全栈2019”Java第七十一章:外部类访问静态内部类成员详解

    难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java第 ...

  3. Linux centos 7安装

    Linux 安装 本章节我们将为大家介绍Linux的安装. 本章节以 centos6.4 为例. centos 下载地址: 可以去官网下载最新版本:https://www.centos.org/dow ...

  4. [ActionScript 3.0] 正则表达式

    正则表达式: 正则表达式最早是由数学家Stephen Kleene在对自然语言的递增研究成果的基础上,于1956提出来的.具有完整语法的正则表达式,主要使用在字符串的格式的匹配方面上,后来也逐渐应用到 ...

  5. os模块详解

    python编程时,经常和文件.目录打交道,这是就离不了os模块.os模块包含普遍的操作系统功能,与具体的平台无关.以下列举常用的命令 1. os.name——判断现在正在实用的平台,Windows ...

  6. svn 冲突Skipped ‘inm/inm/templates‘ -- Node remains in conflict

    svn在删除后,提交,更新操作后可能会报, svn update inm/inm -r 1586 Updating ‘inm/inm‘: Password: Skipped ‘inm/inm/temp ...

  7. 2019.2.14 t3 车辆销售

    用算法求最大生成树,在并查集合并时,把原本的一个根连向另一个 根改成两个根都连向一个新建的节点,并把当前正在处理的边的权值赋给这个新 节点做点权.这样形成的结构会是一棵树. 一个点的答案大致上是树的根 ...

  8. 基于VS快速排序的单元测试

    1.选择开发工具 1.1由于Visual stdio 已经安装,所以运行界面如下图所示: 2.进行单元测试 2.1用Visual stdio 2017创建一个新项目(快速排序)如下图所示: 其中程序如 ...

  9. Http Header之User-Agent

    Http Header之User-Agent User-Agent中文名为用户代理,简称 UA,它是一个特殊字符串头.通过这个标识,用户所访问的网站可以显示不同的排版从而为用户提供更好的体验或者进行信 ...

  10. Java生成树关系的菜单

    1.菜单bean public class Menu { private String id; private String menuname; private String parentid; pr ...