git配置远程仓库

首先下我们需要配置git上我们的用户信息,包括这个用户名称和电子邮件地址,用户名可随意修改,它们用于记录是谁提交了更新,以及更新大家的联系方式。

whthomas@whthomas:~/workplace/gitOne$ git config --global user.name  "whthomas"
whthomas@whthomas:~/workplace/gitOne$ git config --global user.email whthomas93@gmial.com

这里再做一个配置

whthomas@whthomas:~/workplace/gitOne$ git config receive.denyCurrentBranch ignore

 

好了我们开始架设服务器了 首先为了避免我们的项目和其他的文件相冲突,我们新建一个git用户。

root@whthomas:/home/whthomas# adduser git
root@whthomas:/home/whthomas# su git

我们新建一个文件夹 .ssh,并在其目录下新建一个文件authorized_keys,它被用于存放其他用户的公钥(所有人的公钥都要放在这个文件里面,我们可以使用 >> 的方式,把大家的公钥追加进来。)

git@whthomas:~$ mkdir .ssh
git@whthomas:~$ cd .ssh
git@whthomas:~$ touch authorized_keys

放好大家的公钥之后,我们开始使用git用户新建一个仓库了。

git@whthomas:~$ mkdir res.git
git@whthomas:~$ cd res.git/
git@whthomas:~/res.git$ git --bare init

在另一端用户就可以使用自己新建的仓库加入这个远程仓库中去了

whthomas@whthomas:~/workplace/gitu$ git init
初始化空的 Git 版本库于 /home/whthomas/workplace/gitu/.git/
whthomas@whthomas:~/workplace/gitu$ touch README
whthomas@whthomas:~/workplace/gitu$ echo hello >> README 
whthomas@whthomas:~/workplace/gitu$ cat README 
hello
whthomas@whthomas:~/workplace/gitu$ git add .
whthomas@whthomas:~/workplace/gitu$ git commit -m "add a README"
[master (根提交) 59d4695] add a README
 1 file changed, 1 insertion(+)
 create mode 100644 README
whthomas@whthomas:~/workplace/gitu$ git remote add origin git@127.0.0.1:/home/git/res.git
whthomas@whthomas:~/workplace/gitu$ git push origin master 
Counting objects: 3, done.
Writing objects: 100% (3/3), 216 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@127.0.0.1:/home/git/res.git
 * [new branch]      master -> master

如果push的时候出现错误:

ssh: connect to host 127.0.0.1 port 22: Connection refused
fatal: The remote end hung up unexpectedly

这是由于openssl服务器没有安装的问题,使用如下命令安装之后就OK了。

whthomas@whthomas:$sudo apt-get install openssh-server 

安装完成之后,我们再次push代码那么一切都可以ok了。

我们可以去另外一个目录下clone项目,检查push是不是成功。

whthomas@whthomas:~/workplace/gitu$ cd ..
whthomas@whthomas:~/workplace$ git clone git@127.0.0.1:/home/git/res.git
正克隆到 'res'...
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
接收对象中: 100% (3/3), done.
Checking connectivity... done
whthomas@whthomas:~/workplace$ ls
gitu     res     

Ok!  远程仓库搭建成功!这种git服务器搭建方式,非常适合几个人的小型团队协作工作。

附上我们怎么生成ssh密钥。

whthomas@whthomas:~$ ssh-keygen

一路回车键~(当然你要输入密码的话,就不要一路回车了。。。。)

生成的密钥文件会放在用户目录的.ssh目录下。

whthomas@whthomas:~/.ssh$ ls
authorized_keys  id_rsa  id_rsa.pub  known_hosts

id_rsa是我们的私钥, id_rsa.pub是我们的公钥。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值