如果在服務器上直接用 git init
則會自動在當前目錄創建.git目錄
但在本地clone后修改后,不能push,
這是由於git默認拒絕了push操作,需要進行設置,修改.git/config添加如下代碼:
[receive]
denyCurrentBranch = ignore
在初始化遠程倉庫時最好使用 git --bare init
需首先手工創建.git目錄,進入.git目錄后再執行此命令
本地克隆服務器的命令
git clone username@host:/path/to/directory/.git
push后服務器目錄里沒有反應,這時可以在working directory使用
git reset --hard
才能看到push后的內容。
如果執行此命令出現錯誤
fatal: This operation must be run in a work tree
可以在服務器上先執行一下
git config core.bare false
執行完此命令,則本地不能再push到服務端,如若需要再次push 則執行一下
git config core.bare true
可以把以下命令做成腳本,每次push后執行即可實現服務器與本地的文件同步:
git config core.bare false
git reset --hard
git config core.bare true
