2017-06-28 14 views
0

私はMac OS Sierraでgitを使用する方法を学び、ローカルのマシンに両方のリモートリポソリとローカルリポジトリを作成しました。ローカルのリポジトリからリモートのリポジトリにプッシュすることができないのはなぜですか?

I git initリモートレポとgit clone私のローカルレポにあります。私は私の地元のレポに変更を加えたとき、私は、この手順に従っ:

git diff 
git status 
git add -A 
git commit -m "" 
git pull origin master 

は、次にI git push origin masterと私は、このエラーメッセージが表示されました。

Counting objects: 3, done. 
Delta compression using up to 4 threads. 
Compressing objects: 100% (3/3), done. 
Writing objects: 100% (3/3), 340 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 t 
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing int 
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 som 
remote: error: other way. 
remote: error: 
remote: error: To squelch this message and still keep the default behaviour, se 
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'. 
To /Users/iivri.andre/local-repo/../git 
! [remote rejected] master -> master (branch is currently checked out) 
error: failed to push some refs to '/Users/iivri.andre/local-repo/../git' 

これを修正するにはどうすればよいですか?あなたはこの

git init --bare 

などのリモートのgitを作成する必要が

答えて

0

私はこれを修正するにはどうすればよいthis link

1

を見ることができますか?

2つのオプションがあります。まず、あなたが裸のリポジトリにプッシュしているレポを作ることです。これは、裸のクローンとしてリモートを使用するための好ましい方法です。

通常、裸のレポから始めて、git init --bareでクローンを作成します。しかし、あなたは既存のレポを持っているので、最も単純なことは、それの裸のクローンを作ることです。

git clone --bare path/to/that/repo 

今、あなたはそれをクローニングすることによって、またはgit remote set-url origin path/to/the/bare/cloneのいずれかにプッシュし、あなたのリモートとして新しい裸のクローンを使用します。


もう1つの方法は、指示に従って、とにかく押すように指示することです。

cd the/remote/repo 
git config receive.denyCurrentBranch ignore 

これは悪い考えです。プッシュするとリポジトリは更新されますが、チェックアウトされたファイル(つまり作業ディレクトリ)は更新されません。誰かがそのリポジトリを使って作業している場合、非常に混乱するでしょう。あなたの意図がプッシュしてそのレポのチェックアウトを更新する場合、それは動作しません。

0

あなたのリモートリポジトリoriginはベアリポジトリではありません。つまり、コードのチェックアウトバージョンが含まれています。具体的には、チェックアウトされたoriginのブランチが、プッシュしようとしているブランチと同じであることを示すエラーメッセージが表示されます。

あなたがプッシュし、物事の数は具体的には、起こる:

  • コミットが履歴に追加されている
  • 支店ポインタが

を移動している第二の点は、具体的にどのようなエラーメッセージです約です。リポジトリを所有している人(この場合はあなたですが、要件ではありません)は、ブランチmasterがその時点で定義したリポジトリの特定の状態をチェックアウトしています。レポにプッシュすると、masterポインタが新しいコミットを含むように移動します。 gitがあなたのプッシュをそのまま通過することを許可した場合、他の人の作業コピー上のファイルを変更している可能性があります。

別の非裸のレポから、あなたのコミットを取得するには、あなたはあなたに利用可能なオプションの数を持っている:

  • あなたは秒に最初のレポからのリモートを追加し、新しいを取得することができますコミット
    • git remote add feature <path-to-second-repo>
    • git fetch feature
    • git merge feature/master(個人的に、私はこれで--ff専用フラグを使用したい)
  • あなたの非原産のレポのmasterブランチの名前を変更し、
    • git branch -m master feature_master
    • git push origin feature_master
    • CD <path-to-origin>
    • git merge feature_master(再び、私は--ffのみ使用することをプッシュすることができますここをクリック)
  • と同じ名前を変更できます元のリポジトリのブランチ。 origin/renamed_masterにリベースまたはマージする必要がある履歴が存在しないようにする必要があるため、これはお勧めしません。master
関連する問題