LoginSignup
1
1

More than 3 years have passed since last update.

Githubで特定のフォルダのみcloneする方法

Posted at

内容

本記事ではGithub(実際はgitリポジトリならどこでも)で特定のフォルダのみをcloneする
厳密にはcloneではないが、、、

0. clone先のディレクトリ作成

# ディレクトリ作成
$ mkdir hoge
$ cd hoge

1. git初期化

# git初期化
$ git init

2. origin追加

# origin追加
$ git remote add origin piyo.git

3. sparce-checkout有効化

# sparce-checkout有効化
$ git config core.sparsecheckout true

4. sparse-checkout対象の設定

# sparse-checkout対象の設定
# sub_dir 部分はリポジトリのルートからの相対パス
# repository_root/sub_dir/subsub_dir/...のリポジトリツリーにおいて、sub_dirフォルダのみcloneしたい場合は、以下のように設定
$ echo sub_dir > .git/info/sparse-checkout

5. sparse-checkout対象の設定

# sparse-checkout対象の設定
# sub_dir 部分はリポジトリのルートからの相対パス
# repository_root/sub_dir/subsub_dir/...のリポジトリツリーにおいて、sub_dirフォルダのみcloneしたい場合は、以下のように設定
$ echo sub_dir > .git/info/sparse-checkout

5. originをpull

# originをpull
$ git pull origin master

以上

p.s. 少しググると、上記のやり方は古く新しいやり方があるそう・・・

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