前些日子因为某些原因,需要在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. hdu3089 Josephus again|快速约瑟夫环

    题目链接:戳我 貌似是高一昨天的考试题T2?????感觉挺好玩的就搞了搞qwqwq 其实是HDU上面的题啦.... 对于普通的约瑟夫问题,大概是n个人围成一个环,从1开始报数,数到k,那个人出队,最后 ...

  2. ubuntu里面如何以root身份使用图形界面管理文件?

    nautilus 是gnome的文件管理器,但是如果不是root账号下,权限受限,我们可以通过以下方式以root权限使用! 一,快捷键“Ctrl+Alt+t”,调出shell. 二,在shell中输入 ...

  3. 【OCP|052】iZ0-052最新题库及答案整理-第9题

    9.Which is true about the Automatic Diagnostic Repository (ADR)? A) It includes diagnostic data for ...

  4. ie7 a标签强制不换行兼容问题

    a内容错乱如图所示: 解决方法:加个样式就行white-space:nowrap;  最终效果图: 添加了white-space:nowrap 之后, 这样就强制一段文字不会自动换行了.

  5. maven+eclipse+ssm 环境搭建和启动

    该类工程环境搭建和启动方法 ------------------------------------------------------------------------------- 配置 jdk ...

  6. 案例3-ubuntu和centos中自动部署tomcat相关服务的脚本

    涉及redis,mysql,xtrabackup, tomcat 1. ubuntu中 #!/bin/bash #first, change to root #出错立刻中断 set -e apt-ge ...

  7. python为何需要虚拟环境--Python虚拟环境的安装和配置-virtualenv

    一 虚拟环境 virtual environment 它是一个虚拟化,从电脑独立开辟出来的环境.通俗的来讲,虚拟环境就是借助虚拟机docker来把一部分内容独立出来,我们把这部分独立出来的东西称作“容 ...

  8. CSS 两个行内块元素,宽度相加刚好等于父盒子容器的元素,但第二个元素掉在第二行解决办法

    我们可以发现:两个行内块元素,宽度相加刚好等于父盒子容器的元素,但第二个元素掉在第二行,这是什么问题呢? 我们先来看一下效果: <!DOCTYPE html> <html lang= ...

  9. [Alpha]Scrum Meeting#2

    github 本次会议项目由PM召开,时间为4月2日晚上10点30分 时长25分钟 任务表格 人员 昨日工作 下一步工作 木鬼 撰写内置问卷(issue#3) 撰写团队贡献分配计划(issue#39) ...

  10. USART列子

    #include "stm32f10x.h" void USART_INit(void) { GPIO_InitTypeDef GPIO_Initstructe; USART_In ...