LoginSignup
0
0

More than 5 years have passed since last update.

gitでローカルからリモートへpushできなかった時の備忘録

Posted at

ローカルからリモートへpushしようとしたら、エラーが出力されて困ったので同じようなエラーで困った人のための備忘録として記録しておきます。

error: src refspec ブランチ名 does not match any.
error: failed to push some refs to 'https://hoge@bitbucket.org/hogerin/test_repository.git'

経緯

過去にbitbucket既にpushしたローカルbranchから再度以下のようなコマンドでremote上のbranchにpushしようとしたらこのエラーがでてしまいました。

git push origin ブランチ名

原因

git push の正式な使い方は

git push origin リモートのブランチ名:リモートブランチ名

のように[push元のブランチ:push先のブランチ]を指定しなければいけなかったのを忘れていた。
実は今回、

① リモートのmasterからbranchを作成
②①で作成したbranchをローカルへpull
③作業が済んだので②で作成したブランチへpush
④①で作成したbranchの用が済んだのでリモート上で削除
⑤②でpullしてきたbranchをそのまま作業に使う
⑥新しいbranchをリモート上で作成し、pushを試みる
⑦エラーを吐く

というような背景があった。

解決方法

ローカルのAブランチからリモートのAブランチにpushするときのみ、

git push origin ブランチ名

このコマンドが使えるので、
ローカルブランチAからリモートブランチBへpushするときは

git push origin リモートのブランチ名:リモートブランチ名

このように明示的に指定してあげなければいけなかったという結果なので、

git push origin リモートのブランチ名:リモートブランチ名

これで正しくpush出来ました。
てへ。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0