Git - 远程库的创建与认证
前些日子因为某些原因,需要在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 - 远程库的创建与认证的更多相关文章
- Git版本库的创建(Ubuntu)
在Ubuntu上学习Git随笔. 一. git 仓库的安装 git 在终端用git命令查看Ubuntu是否安装git版本库,如果没有安装,最新版本(Ubuntu18.04)会提示用下面命令进行安装. ...
- git 远程库 创建私钥
1.创建SSH Key.在用户主目录下,看看有没有.ssh目录,如果有,再看看这个目录下有没有id_rsa和id_rsa.pub这两个文件,如果已经有了,可直接跳到下一步.如果没有,打开Shell(W ...
- git 远程仓库 轻松创建
很多时候,为了方面管理我们写的代码,我们采用git 远程仓库来进行管理和备份.防止代码被他人篡改或删除.那如何来进行创建远程仓库呢? 1.我们必须有一个远程服务器端,在这里可以把任意一台电脑作为服务器 ...
- git远程库代码版本回滚方法
最近使用git时, 造成了远程库代码需要回滚到之前版本的情况,为了解决这个问题查看了很多资料. 问题产生原因: 提交了错误的版本到远程库. 以下是解决的方法, 供大家参考: 1.对本地代码库进行回滚 ...
- Git远程库
要关联一个远程主机,使用命令 git remote add origin <url> : 删除远程主机,使用命令 git remote rm origin ; git push 的一般形式 ...
- 将本地项目上传到git远程库(初始化)
准备条件: 首先,有一个远程仓库地址,本文中的地址为“http://git.xxxxxxxx.net.cn/jacun/imagegrap.git”; 第一步:在本地创建初始化仓库: git init ...
- git远程库GitHub
首先,注册一个GitHub(github.com)帐号,免费获得Git远程仓库 由于本地Git仓库和GitHub仓库之间的传输是通过SSH加密的,所以,需要一点设置: 第1步:创建SSH Key.在用 ...
- Git远程库版本回滚
在git的一般使用中,如果发现错误的将不想staging的文件add进入index之后,想回退取消,这就叫做git代码库回滚: 指的是将代码库某分支退回到以前的某个commit id.可以使用命令:g ...
- git 远程库和url
我们使用 git remote add origin <url> 来关联远程主机,这个origin就是关联的远程主机名,如果我们想同时关联两个远程主机,我们可以用 git remote a ...
随机推荐
- 编写高质量JS代码上
想写出高效的javascript类库却无从下手: 尝试阅读别人的类库,却理解得似懂给懂: 打算好好钻研js高级函数,但权威书上的内容太零散, 即使记住“用法”,但到要“用”的时候却没有想“法”. 也许 ...
- numpy.reshape()
数组新的shape属性应该要与原来的配套,如果等于-1的话,那么Numpy会根据剩下的维度计算出数组的另外一个shape属性值.
- better-scroll在vue中的应用
在我们日常的移动端项目开发中,处理滚动列表是再常见不过的需求了,以滴滴为例,可以是这样竖向滚动的列表,如图所示: 微信 —> 钱包—>滴滴出行”体验效果. 什么是 better-scrol ...
- [SinGuLaRiTy] 关于博客
由于博主主要使用Chrome内核的浏览器进行博客页面的代码优化,因此有些功能可能会因为浏览器的差异而无法正常运行,博主对此也非常无奈啊:Windows的IE浏览器的兼容性实在是太差了...... 尽管 ...
- 外网域名映射内网Ip 内网使用外网域名的https证书
用nslookup www.baidu.com nslookup www.qq.com 15.64.64.53 测试了内网的dns可以解析外网域名 那么我买个外网域名,再对这个外网域名买个证书,然后外 ...
- jxl读取excel
String path=""; String path2=""; File file = new File(path); File file2 = new Fi ...
- python模块与包详解
<1>.模块:任何 *.py 的文件都可以当作模块使用 import 导入 >>>improt test >>>b=test.a() >> ...
- css加载顺序
最近发现个有意思的事情,印象中的是css中class后面会覆盖前面的, 于是写了代码 div{ width: 100px; height: 100px; } .red{ background-colo ...
- JavaSwing概述
GUI(Graphic User Interface)为程序提供图形界面,它最初的设计目的是构建一个通用的GUI,使其能在所有平台上运行.在Java1.0中基础类AWT(Abstract Window ...
- Vue项目中使用HighChart
记:初次在Vue项目中使用 HighChart 的时候要走的坑 感谢这位哥们的思路 传送门 Vue-cli项目使用 npm install highcharts --save 让我们看看 highch ...