3
1
記事投稿キャンペーン 「2024年!初アウトプットをしよう」

git clone --depth をしたら checkout できなくなった

Posted at

前提

重たいリポジトリを扱っていたので、--depthオプションを使ってクローンした

$ git clone --depth 1 <リポジトリ>

checkout時にエラーが

$ git checkout -b <ブランチ名> origin/<ブランチ名>
fatal: 'origin/<ブランチ名>' is not a commit and a branch '<ブランチ名>' cannot be created from it

原因

git configのfetch時のrefspecがmainブランチに限定されていた

自動生成のgit config

...
remote.origin.url=git@github.com:Minto312/<リポジトリ名>

                                 mainブランチに限定されている
                                 ↓                        ↓
remote.origin.fetch=+refs/heads/main:refs/remotes/origin/main
branch.main.remote=origin
...

修正する

$ git config remote.origin.fetch +refs/heads/*:refs/remotes/origin/*

最後に

"2024年!初アウトプットをしよう"!ということで、人生初アウトプットをしてみました!
私が書く記事でエラーの苦しみがマシになればいいなーと思います
訂正などあれば教えてください!

3
1
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
3
1