LoginSignup
1
1

More than 3 years have passed since last update.

Git 必要なディレクトリだけ checkoutする

Posted at

環境

win10, git 2.28.0.windows.1

手順

①作業ディレクトリに checkoutするディレクトリを作成して そこに移動
②以下 git コマンド作業

→ git初期化 必要なら git-config user.nameとか 設定しておく

> git init

→ sparse-checkout を有効化

> git config core.sparsecheckout true

→ sparse-checkoutファイル作る

$ touch .git/info/sparse-checkout (linux)
> New-Item -Type File .git/info/sparse-checkout (win-PowerShell)

→ <パターン>は checkoutしたい ディレクトリパス

> git sparse-checkout add <パターン>
e.g.) git sparse-checkout add directory/path

→ 指定パターン確認 <パターン>が表示されればおk

> git sparse-checkout list
> git remote add origin <リポジトリのURL>
> git pull origin <ブランチ名>
> git pull origin master

③pullしたら リポジトリの<パターン>(directory/path)だけcheckoutされる


参考)

git sparse checkout で clone せずに一部のサブディレクトリだけを pull/checkout する https://mseeeen.msen.jp/git-sparse-checkout/

リポジトリの一部だけcheckoutするGitコマンド:sparse-checkout - はんなりと、ゆるやかに https://iucstscui.hatenablog.com/entry/2020/05/21/090321

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