Linux, 工作, 生活, 家人

Programming

[GIT] 將現有的目錄改成 bare 並且修改 remote server

git 如果從另一個目錄 clone 出來, 兩邊都有 source code, 是不能直接 master push 到 master 的.
會出現錯誤訊息
[TEXT]
git push error ‘[remote rejected] master -> master (branch is currently checked out)’
[/TEXT]

這時可以產生另一個 bare 目錄, 然後到 git 目錄內下指令, 將該目錄變成 bare
[BASH]
# cp -a (path_to_source_dir) (path_to_bare_dir)
# cd (path_to_bare_dir)
# git config –bool core.bare true
# rm (all source code)
# mv .git/* .
# rmdir .git
[/BASH]

這樣就可以了.

原來的目錄可以修改 remote url 的方式指到新的目錄
[BASH]
# cd (path_to_source_dir)
# git remote set-url origin //(path_to_bare_dir)
[/BASH]

這時有 source code 的目錄還是用 git push/pull 更新 source code.
如果是 bare 的話就是 git push, git fetch/merge 更新 source code.

Ref web.
http://stackoverflow.com/questions/2816369/git-push-error-remote-rejected-master-master-branch-is-currently-checked
http://stackoverflow.com/questions/2432764/how-to-change-a-remote-repository-uri-using-git

發佈留言