這看起來很愚蠢,但我無法弄清楚。用於克隆或添加遠程服務器的指令,或推送到克隆的存儲庫。但我試圖找出如何在服務器上的共享目錄中設置git存儲庫,並讓其他人在其個人目錄中的克隆進行協作。在單臺服務器上使用git,即沒有真正的遠程原點
這是我已經試過:
[email protected]:~$ mkdir mainrepo
[email protected]:~$ cd mainrepo/
[email protected]:~/mainrepo$ echo "inital entry" > text.txt
[email protected]:~/mainrepo$ git init
Initialized empty Git repository in /home/abalter/mainrepo/.git/
[email protected]:~/mainrepo$ git add text.txt
[email protected]:~/mainrepo$ git commit -m "initial commit"
[master (root-commit) fb829d6] initial commit
1 file changed, 1 insertion(+)
create mode 100644 text.txt
[email protected]:~/mainrepo$ cd ..
[email protected]:~$ git clone mainrepo/ userrepo
Cloning into 'userrepo'...
done.
[email protected]:~$ cd userrepo/
[email protected]:~/userrepo$ echo "users addition" >> text.txt
[email protected]:~/userrepo$ git commit -am "users addition"
[master 3d4ea94] users addition
1 file changed, 1 insertion(+)
[email protected]:~/userrepo$ git add remote origin ../mainrepo/
fatal: ../mainrepo/: '../mainrepo/' is outside repository
[email protected]:~/userrepo$ git push origin master
Counting objects: 5, done.
Writing objects: 100% (3/3), 267 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
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 /home/abalter/mainrepo/
! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to '/home/abalter/mainrepo/'
[email protected]:~/userrepo$
顯然我錯過了一步,但我不知道它是什麼。
編輯 我意識到它應該是git remote add origin ../mainrepo
。但是
[email protected]:~/userrepo$ git remote add origin ../mainrepo
fatal: remote origin already exists.
[email protected]:~/userrepo$
如果它已經存在,爲什麼我不能推它呢?
謝謝!我不知道如何創建'--bare'庫。 – abalter