搭建GIT服务器仓库

来源:互联网 发布:淘宝卖什么利润大 编辑:程序博客网 时间:2024/06/05 17:36

新开了一个项目,现在需要将代码放在公司GIT服务器上面。所以这里需要了一些问题。。记录一下。
因为原来公司这边的服务器的git用户都是创建好的。这里没有创建。需要的可以看看:http://www.cnblogs.com/zhoug2020/p/5789041.html。这个博客。
我是直接从创建仓库那里开始了。。通过查找搭建GIT服务器仓库的教程,但是教程有很多问题。导致一直失败。所以这里就写一份本人自己的一些流程方法,供大家参考。

1.进入到git服务器。(比如我这边进入是 执行命令: ssh username@192.111.111.111)..username是配置的用户名。再写上自己的git服务器ip。这里会提示输入密码。

2.进到git服务器后,创建工程的文件夹。执行命令:mkdir ProjectName。

3.进入到创建的工程文件夹。执行命令:cd ProjectName。

4.初始化一个git仓库。。

4.1。如果不执行 touch Readme、git add Readme的操作的话。不管是拉取还是其他操作都会出现"This operation must be run in a work tree"错误。网上很多教程是没有这个步骤的,。被坑惨了。

//执行下方4个命令touch Readme
//网上还有 git --bare init的方法。如果执行git --bare init初始化的话。在git add Readme这部会提示“This operation must be run in a work tree”错误。//如果不执行 touch Readme、git add Readme的操作的话。不管是拉取还是其他操作都会出现"This operation must be run in a work tree"错误。网上很多教程是没有这个步骤的,。被坑惨了。git initgit add Readmegit commit -m 'initial commit' Readme

5.进入到git。修改配置文件。执行命令:cd .git(要在ProjectName目录下执行)

6.修改配置文件。config。。执行命令:vim config

7.添加相关配置信息。在config文件内添加:

 [receive]    denyCurrentBranch = ignore

7.1。如果不添加配置信息的话。会在push的时候出现错误:

//推送被拒绝然后输出的错误信息[remote rejected] master -> master (branch is currently checked out)remote: error: refusing to update checked out branch: refs/heads/masterremote: error: By default, updating the current branch in a non-bare repositoryremote: error: is denied, because it will make the index and work tree inconsistentremote: error: with what you pushed, and will require 'git reset --hard' to matchremote: error: the work tree to HEAD.remote: error:remote: error: You can set 'receive.denyCurrentBranch' configuration variable toremote: error: 'ignore' or 'warn' in the remote repository to allow pushing intoremote: error: its current branch; however, this is not recommended unless youremote: error: arranged to update its work tree to match what you pushed in someremote: error: other way.remote: error:remote: error: To squelch this message and still keep the default behaviour, setremote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.To git@192.168.1.X:/var/git.server/.../web ! [remote rejected] master -> master (branch is currently checked out)error: failed to push some refs to 'git@192.168.1.X:/var/git.server/.../web'

8.创建完git仓库了。。这时候要给用户赋权限。不然的话,不能对他进行操作。执行命令:chown -R username .git(这个命令是在ProjectName文件夹的路径后执行的。注意.git的路径是不是对的。)

9.完成整个步骤。这是你通过clone等命令或者使用SourceTree工具将git仓库保存到本地后,在相应文件夹添加或者修改内容后就能push上去了。

PS:git是一个很好的源码管理工具,公司内部的话,搭建服务器的git仓库是很有必要的。所以这次的搭建仓库成功还是很有成就感的。哈。其实主要的就3个地方要注意:

1.权限有没有赋给用户

2.Readme文件有没有添加。

3.config配置文件有没有配置对。

 

谢谢。

 

原创粉丝点击