しごとのはなし

web関連の仕事の話をメモ的に。

gitのリモートブランチに自分のブランチをpushしたよ、というはなし

今度のプロジェクトでお恥ずかしながら初めて本格的なgit運用。正直言うと、ブランチ切って修正+master にmergeとかrebaseとかすらしたことなかった...(照

 

そういうわけで備忘録として今までやったことなかったことをメモしていくシリーズです。

 

要求

リモートにfeature/witty-testブランチを作ってもらったので、自分のテストコードのブランチtest-with-wkをpushしたい

 

やったこと

とりあえず、リモートブランチに自分のブランチをpushする書式は

git push (remote) (my-branch):(remote-branch)

 なので

$ git push origin test-with-wk:feature/witty-test

とやってみたところ

To https://myreposerver.com/git/our-project/

 ! [rejected]        test-with-wk -> feature/witty-test (non-fast-forward)

error: failed to push some refs to

'https://myreposerver.com/git/our-project/'

hint: Updates were rejected because a pushed branch tip is behind its remote

hint: counterpart. Check out this branch and 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. 

と怒られた。

どうやらリモートブランチは自分のブランチと別の親だったらしいので、親を一致させるためにマージが必要みたいだった。なので自分のブランチにリモートブランチの状態をアップデート。

$ git fetch origin (<-ちょっとあやしい)  

 

 

でリモートリポジトリoriginの状態を取得。これをtest-with-wkブランチに反映させたいので

$ git checkout test-with-wk

$ git merge origin/feature/witty-test

として、test-with-wkの親とfeature/witty-testの親を一致させる。そしてもう一度

$ git push origin test-with-wk:feature/witty-test

を実行したところ

Counting objects: 1586, done.

Delta compression using up to 4 threads.

Compressing objects: 100% (1542/1542), done.

Writing objects: 100% (1580/1580), 3.71 MiB | 428.00 KiB/s, done.

Total 1580 (delta 262), reused 0 (delta 0)

remote: Scanning pack: 100% (1580/1580), done.

remote: Storing objects: 100% (1580/1580), done.

remote: Processing commits: 100% (2/2), done.

To https://myreposerver.com/git/our-project/

   ed5655e..fc87037  test-with-wk -> feature/witty-test 

で成功!