前些日子因为某些原因,需要在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. 数据库客户端工具Oracle SQL Developer

    Oracle SQL Developer是Oracle官方提供的数据库连接工具.不仅可以连接自己的数据库(Oracle),而且还可以连接多种其他的数据库(比如:Access.MySQL.SQL Ser ...

  2. Binder学习笔记(一)

    网上看了很多关于binder的文章,但我还是想把自己的心路历程记录下来,有些是跟着别人的脚步领略险峻风景,有些则是自己只身探入代码深处打捞出的收获.我不确定是否全部融会贯通,更担心一两个月后会完全不记 ...

  3. Oracle ocp 12c-071最新考试题库及答案-1

    choose the best answer: View the Exhibit and examine the structure of the CUSTOMERS table. CUSTOMER_ ...

  4. 各大SRC中的CSRF技巧

    本文作者:i春秋签约作家——Max. 一.CSRF是什么? CSRF(Cross-site request forgery),中文名称:跨站请求伪造,也被称为:one click attack/ses ...

  5. 搭建sftp并设置不同权限的多个用户

    一, 设置相关用户,用户组,ssh配置文件 mkdir -pv /opt/ftpsite/{admin,user1,user2} groupadd sftpadmins groupadd sftpus ...

  6. jxl读取excel

    String path=""; String path2=""; File file = new File(path); File file2 = new Fi ...

  7. POJ3074 Sudoku

    POJ3074 Sudoku 与POJ2676相比,这一题搜索时每一步都找到最好确定的点进行枚举 对于每行.每列.每个九宫格,都分别用一个9位二进制数保存还有那些数还可以填 对于每个位置,将其所在行. ...

  8. 启动MacOS 本地服务

    MacOS 自带Apatch服务器, 在浏览器输入 http://127.0.0.1/  出现it works,代表访问成功 一. 启动 启动 sudo apachectl start 重启 sudo ...

  9. nginx应用

    windows: 启动:start nginx 退出:nginx -s quit 检查配置是否正确:nginx -t -c ./conf/nginx.conf 查看是否在运行:tasklist /fi ...

  10. Java框架-mybatis01查询单个数据

    1.什么是mybatis? mybatis是一个基于Java的持久层框架. 2.持久化:数据从瞬时状态变为持久状态. 3.持久层:完成持久化工作的代码块.---dao 4.Mybatis是帮助程序员将 ...