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
手順
1
とりあえず作りたいに異動して設定ファイルを作る
git init --bare hogeProject.git
2
ローカルpcでgittortoiseをつかってるのでその設定ファイル>リモートリポジトリ設定?
こういうのになってるのをディレクトリ名とかさっき作ったのに変える。
url = sakura:/home/user1/gitRemote/hogeProject.git
3
クローンする
git clone /home/user1/gitRemote/hogeProject.git
4
割と一瞬でできあがり
5
自動的にプルさせたいので.gitの設定ファイルの下にあるhooksをいじる
post-receive.sampleのコピーしてpost-receiveにする
6
中身にこれをかく
cd /home/user1/myProject/hogeProject
git --git-dir=.git pull
7
テストでローカルのをプッシュしてみると反映されてるはず