LoginSignup
0
0

More than 3 years have passed since last update.

Gitでリモートに新規作成したbranchがgit fetchしてもローカルで追跡出来ずハマった話

Last updated at Posted at 2020-05-22

はじめに

私が午前中を溶かした、git fetchでハマった話を忘備録を兼ねて記載する。

発生した事象

git fetchしても新規作成したブランチ名が表示されない事象に遭遇した。

具体的には、以下のように作業を進めていた。
①リモートリポジトリをローカルにクローン
②リモートリポジトリで新規ブランチを作成
③クローン済みのローカルリポジトリに②で作成したブランチをチェックアウト

この際、③にてブランチのチェックアウトをしようと、
git fetchでリモートブランチの情報取得後、
git branch -aでリモートブランチを確認したが、新規作成したリモートブランチ名が表示されない。
そのため、チェックアウトも出来ずハマってしまった。

原因

./git/config内のfetch対象の指定が、以下のようにブランチ毎になっていた。

[remote "origin"]
    url = https://hogehohehoge
    fetch = +refs/heads/hoge:refs/remotes/origin/hoge
    fetch = +refs/heads/hoge2:refs/remotes/origin/hoge2

解決方法

以下のように、fetch対象のbranchをリモート全体に指定する事で、
クローン後に新規作成した時にも情報を取得してくれるようになった。

[remote "origin"]
    url = https://hogehohehoge
    fetch = +refs/heads/*:refs/remotes/origin/*

参考文献

こちらのページに大変助けられました。ありがとうございます…!

『Git』10.5 Gitの内側 - Refspec
https://git-scm.com/book/ja/v2/Git%E3%81%AE%E5%86%85%E5%81%B4-Refspec

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