设为首页 收藏本站
查看: 765|回复: 0

[经验分享] Git 远程仓库搭建

[复制链接]

尚未签到

发表于 2018-1-15 13:51:29 | 显示全部楼层 |阅读模式
  大名鼎鼎的git就不多做介绍了,总之。我们使用git来作为项目的一个版本控制工具,多人开发的项目的时候会轻松很多。
  安装git
  

whthomas@whthomas:~/workplace/gitOne$sudo apt-get install git  

  Windows下,可以在http://msysgit.github.io/上下载安装包。
  同时Windows上也可以执行shell哟!
  话不多说,下面我们来配置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是我们的私钥,>

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-435337-1-1.html 上篇帖子: git 添加到环境变量 下篇帖子: Git命令详解
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表