gitコマンドでローカルとリモートの同期ができなかった原因(私の場合)
gitコマンドは間違っていないのになぜかローカルとリモートの同期が出来なくて困った時の原因と対策。
上手くいかなかったコマンド
GitHubにリポジトリ(リモート)を作って一番最初にやるこれ。
$ git remote add origin https://github.com/natsumo/test.git
までは出来たんだけど、なぜか
git push -u origin master
が出来ない。。cloneも同じく出来なかった。
原因
以下remoteの設定を確認してみると...
$ git config --list ...省略... user.name=natsumo user.email=*****@***.*** remote.origin.url=https://github.com/natsumo ...省略... remote.origin.url=https://github.com/natsumo/test.git $ git remote -v origin https://github.com/natsumo (fetch) origin https://github.com/natsumo (push) origin https://github.com/natsumo/test.git (push)
なんかおかしい。remote.origin.urlが2つある。
$ git remote rm origin
で削除してみても、
$ git config --list ...省略... user.name=natsumo user.email=*****@***.*** remote.origin.url=https://github.com/natsumo ...省略... $ git remote -v origin https://github.com/natsumo (fetch) origin https://github.com/natsumo (push)
消えない!?... あ...、わかった...。globalに設定してしまっているようだ...(いつやったんだろう...)
$ git config --global --list remote.origin.url=https://github.com/natsumo
改善方法
globalの設定ファイルを直接触って、remote.origin.url=https://github.com/natsumo
を消す。
$ git config --global --edit
出来たら確認してみる。
$ git config --global --list
remote.origin.url=https://github.com/natsumo
が無事消えていればOK!
...恥ずかしい、、きっと訳も分からず --global
をつけて設定してしまったんだろうな。。
とりあえず一件落着👍