最新搭建GIT服务器仓库

新开了一个项目,如今须要将代码放在公司GIT服务器上面。因此这里须要了一些问题。。记录一下。
由于原来公司这边的服务器的git用户都是建立好的。这里没有建立。须要的能够看看:http://www.cnblogs.com/zhoug2020/p/5789041.html。这个博客。
我是直接从建立仓库那里开始了。。经过查找搭建GIT服务器仓库的教程,可是教程有不少问题。致使一直失败。因此这里就写一份本人本身的一些流程方法,供你们参考。html

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

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

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

4.初始化一个git仓库。。服务器

4.1。若是不执行 touch Readme、git add Readme的操做的话。无论是拉取仍是其余操做都会出现"This operation must be run in a work tree"错误。网上不少教程是没有这个步骤的,。被坑惨了。less

//执行下方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 init
git add Readme
git commit -m 'initial commit' Readme

 

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

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

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

 [receive]
    denyCurrentBranch = ignore

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

//推送被拒绝而后输出的错误信息
[remote rejected] master -> master (branch is currently checked out)
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'.
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配置文件有没有配置对。

 

谢谢。

相关文章
相关标签/搜索