Git update


Partial clone of git repository

Example of how to clone a single directory from Git repository.

$ cd whatdidilearn.today

$ git init
Initialized empty Git repository in /www/whatdidilearn.today/.git/

# Enable saving of entered credentials
$ git config credential.helper store

$ git remote add -f origin https://<repository URL>
Updating origin
Username for 'https://<git server>':
Password for 'https://<username@git server>':
remote: Enumerating objects: 1100, done.
remote: Counting objects: 100% (1100/1100), done.
remote: Compressing objects: 100% (661/661), done.
remote: Total 1100 (delta 357), reused 949 (delta 265)
Receiving objects: 100% (1100/1100), 12.98 MiB | 28.39 MiB/s, done.
Resolving deltas: 100% (357/357), done.
From https://<repository URL>
 * [new branch]      hugo       -> origin/hugo
 * [new branch]      master     -> origin/master

# Enable sparse checkout
$ git config core.sparseCheckout true

# Specifiy directory to checkout
$ echo public >> .git/info/sparse-checkout

# pull only the specified directory from repository
# note: current branch in our repository is 'hugo', default would be 'master'
$ git pull origin hugo
remote: Enumerating objects: 272, done.
remote: Counting objects: 100% (272/272), done.
remote: Compressing objects: 100% (68/68), done.
remote: Total 270 (delta 119), reused 270 (delta 119)
Receiving objects: 100% (270/270), 266.68 KiB | 11.11 MiB/s, done.
Resolving deltas: 100% (119/119), completed with 2 local objects.
From https://<repository URL>
 * branch            hugo       -> FETCH_HEAD
   399b8b5..b5a08f8  hugo       -> origin/hugo

# Only the specified directory was cloned
$ ls -l
total 4
drwxrwxr-x 14 user user 4096 Jun 13 09:41 public
Comment on this article using form below. Requires email login only for authentication. HTML forbidden, Markdown only.