LoginSignup
0
0

More than 1 year has passed since last update.

bareリポジトリをnon-bareリポジトリに変える

Last updated at Posted at 2022-02-17

bareリポジトリとは

  • bareリポジトリは、公開されたリポジトリを管理する人が扱うもの
  • 管理ファイルがリポジトリ名.gitに入っている
    • 普通の(non-bareな)リポジトリなら.gitという隠しディレクトリになってる
  • 他のソースファイルとかはない(チェックアウトされてない)

bareリポジトリを.gitに改名してgit config core.bare falseすると普通のnon-bareリポジトリになるのでcheckoutなどの操作ができるみたいです。

bashでの操作

bareリポジトリを取ってきてnon-bareにする
git clone --bare <URL等>/foo.git
# foo.git というディレクトリ(bareなリポジトリ)が手に入る
mv foo.git .git
git config core.bare false

foo.gitのディレクトリ名を.gitにして、configでnon-bareにするだけです。

補足

bareリポジトリを取ってきてnon-bareにする(コメント付き)
git clone --bare <URL等>/foo.git
# ここで git status すると以下のエラー (ここで実行するなら".git"という名でないと認識されないので)
#   fatal: not a git repository (or any of the parent directories): .git
mv foo.git .git
# ここで git status すると以下のエラー (bareで実行すべきでないので)
#   fatal: this operation must be run in a work tree
git config core.bare false
git status
# 成功(checkout等をしてないので全ファイルを削除したという旨の結果が出る)

使う場面

gitの仕組みが気になった時?
他にはあまりないと思う。non-bareなものが欲しければ普通にcloneすればいいはず。
ただ、bareだと使用できるコマンドに制限があるので「手元になぜかbareなリポジトリだけあって色々調べたい」という場面なら試していいかもしれない。
と思ったけどgit clone <ローカルのパス>でそのリポジトリをクローンすればいいだけな気もする。

参考

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