最新搭建GIT服務器倉庫


新開了一個項目,現在需要將代碼放在公司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 init
git add Readme
git 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/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配置文件有沒有配置對。

 

謝謝。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM