前些日子因为某些原因,需要在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. pageadmin自助建站 网站目录权限的设置方法

    在用pageadmin网页设计的时候遇到各种问题可以参考官网教程网站目录权限的设置方法 网站目录必须设置读取和写入权限,否则后台解压,删除文件,在线上传等功能都无法正常使用,下面讲解本机和服务器配置目 ...

  2. Ubuntu16.04实用python脚本 - 启动nautilus(Gnome的文件管理器)!

    nautilus是Gnome的图形的文件管理器,可以很方便管理各种文件,但是通常我们不是在root用户下,如果想在root下使用,必须在shell里面输入命令: sudo nautilus 这样做固然 ...

  3. Mysql数据操作《二》单表查询

    单表查询的语法 SELECT 字段1,字段2... FROM 表名 WHERE 条件 GROUP BY field HAVING 筛选 ORDER BY field LIMIT 限制条数 关键字的执行 ...

  4. JAVA分解质因子

    /*题目 分解质因数(5分) 题目内容: 每个非素数(合数)都可以写成几个素数(也可称为质数)相乘的形式,这几个素数就都叫做这个合数的质因数.比如,6可以被分解为2x3,而24可以被分解为2x2x2x ...

  5. java 去最后一位字符 str.substring(0,str.length()-1)

    String str = " 中国, 美国 , 意大利 ";String[] arr = str.split(",");for(int i1 =0;i1< ...

  6. 如何提高scrapy的爬取效率

    提高scrapy的爬取效率 增加并发: 默认scrapy开启的并发线程为32个,可以适当进行增加.在settings配置文件中修改CONCURRENT_REQUESTS = 100值为100,并发设置 ...

  7. 三,PHP中错误日志display_errors与error_reporting配置

    1,display_errors display_errors 错误回显,一般常用语开发模式,但是很多应用在正式环境中也忘记了关闭此选项.错误回显可以暴露出非常多的敏感信息,为攻击者下一步攻击提供便利 ...

  8. MySQL直接导出CSV文件,并解决中文乱码的问题

    需求: 需要导出hr_users 表中的部分字段的数据,以前是用PHP写脚本,然后导出CSV文件. 在MySQL中,它自己就能导出CSV文件 ,只不过是有如下几个问题需要大家解决. 1. 生成文件不成 ...

  9. 【实战分享】安卓app测试的一些记录

    一.app代码未混淆1.使用7zip解压apk文件2.执行命令:dex2jar.bat apk解压后文件夹中的classes.dex文件3.上述命令执行后会在apk文件夹中生成java源码文件clas ...

  10. FreeRTOS-02任务挂起和恢复

    根据正点原子FreeRTOS视频整理 单片机:STM32F207VC FreeRTOS源码版本:v10.0.1 任务挂起和恢复API函数: 工程列表: 1. main.c /**/ #include ...