チェ・ゲバムラの日記

脱犬の道を目指す男のブログ

Gitでプッシュすると[rejected]されてしまう時はcloneし直そう

プッシュしたらこんなのが出てできなかった。

git.exe push --progress "origin" ブランチ名:ブランチ名

Everything up-to-date
To ssh://user@IPアドレス:22/var/www/html/hoge/hogehogegit
! [rejected] ブランチ名 -> ブランチ名 (fetch first)
error: failed to push some refs to

'ssh://user@IPアドレス:22/var/www/html/hoge/hogehogegit'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

 

 

なんかフェッチして直る時もあるっぽいけどなんかうまくいかないときは、

素直にcloneし直そう。。

ローカルじゃなくてリモートの方で。

 

構成はこんなかんじ

html/A/xxxxx.git

html/A/xxxxx

 

手順

とりあえず作りたいに異動して設定ファイルを作る

git init --bare hogeProject.git

 

 

ローカルpcでgittortoiseをつかってるのでその設定ファイル>リモートリポジトリ設定?

こういうのになってるのをディレクトリ名とかさっき作ったのに変える。

url = sakura:/home/user1/gitRemote/hogeProject.git

 

 

クローンする

git clone /home/user1/gitRemote/hogeProject.git

 

割と一瞬でできあがり

 

自動的にプルさせたいので.gitの設定ファイルの下にあるhooksをいじる

post-receive.sampleのコピーしてpost-receiveにする

 

中身にこれをかく
cd /home/user1/myProject/hogeProject
git --git-dir=.git pull

 

テストでローカルのをプッシュしてみると反映されてるはず