新開了一個項目,如今須要將代碼放在公司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配置文件有沒有配置對。
謝謝。