GitHub.comのリポジトリの特定のディレクトリ以下をダウンロードできる「GitHub clone」

大きなGitリポジトリをcloneすると時間がかかります.最新のものだけが欲しい場合は --depth オプションがありますが,リポジトリの一部のディレクトリ以下だけが欲しい時には使えません.そういうときにGitHub cloneを使うと,特定のディレクトリ以下だけをダウンロードできて便利そうです.

少し試してみました.

$ pip3 install git+git://github.com/HR/github-clone#egg=ghclone (1)
$ ghclone (2)
Usage:
  ghclone <url> [-t | --token=<token>]
  ghclone (-h | --help)
  ghclone (-v | --version)
$ ghclone https://github.com/torvalds/linux/tree/master/tools/usb/usbip (3)
Cloning into 'usbip'...
done.
$ cd usbip
$ ls -A (4)
.gitignore  AUTHORS  COPYING  INSTALL  Makefile.am  README  autogen.sh  cleanup.sh  configure.ac  doc  libsrc  src  vudc
$ git status (5)
fatal: not a git repository (or any of the parent directories): .git
$ cd ..
$ ghclone https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/usb (6)
Invalid GitHub URI
  1. pipで導入する(もしPATHが通ってなければ ~/.local/bin を加える)
  2. USAGE
  3. Linux Kernelの一部だけをダウンロード
  4. ダウンロード内容確認
  5. Git管理はされていない
  6. GitHub以外のGitリポジトリに対して実行すると失敗する

GitHub.comのAPIを利用しているのでGitHub.com以外では使えませんが便利そうです.

似たものにBitBacketで同様のことができる,「bb-clone」というものもあるようです.

環境
$ ghclone -v
1.2.0
$ dpkg-query -W git python3-pip python3
git     1:2.20.1-2+deb10u3
python3 3.7.3-1
python3-pip     18.1-5+rpt1
$ lsb_release -dr
Description:    Raspbian GNU/Linux 10 (buster)
Release:        10
$ uname -a
Linux raspberrypi 5.10.11-v7+ #1399 SMP Thu Jan 28 12:06:05 GMT 2021 armv7l GNU/Linux
$ cat /proc/device-tree/model ;echo
Raspberry Pi 3 Model B Rev 1.2

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

To respond on your own website, enter the URL of your response which should contain a link to this post's permalink URL. Your response will then appear (possibly after moderation) on this page. Want to update or remove your response? Update or delete your post and re-enter your post's URL again. (Find out more about Webmentions.)