33
44This script clones a subdirectory of a github/gitlab repository.
55
6- # Usage
7- ## Quick test
8- Test the script with the example config file.
9- By the end of the execution, you will see a ` tmp ` directory containing the subfolder of the example repository.
6+ - [ Install] ( #install )
7+ - [ Using the comand line options] ( #using-the-comand-line-options )
8+ - [ Clone from public repositories] ( #clone-from-public-repositories )
9+ - [ Clone from private repositories] ( #clone-from-private-repositories )
10+ - [ Using a configuration file] ( #using-a-configuration-file )
11+ - [ Configuration variables] ( #configuration-variables )
12+ - [ Mandatory variables] ( #mandatory-variables )
13+ - [ Variables for ** private repositories** ] ( #variables-for-private-repositories )
14+ - [ Optional variables] ( #optional-variables )
15+
16+ # Install
17+ Clone this repository
1018``` zsh
11- ./git-partial-clone.sh --file example.conf
19+ sudo apt install -y git
20+ git clone https://github.com/lu0/git-partial-clone.git
1221```
13- ## Install
1422Install the script and autocompletion rules.
1523``` zsh
16- ./install.sh
24+ cd git-partial-clone/ && ./install.sh
1725```
18- Then you can execute the script from any directory with your custom config file and use ` TAB ` to autocomplete the CLI options.
26+ Then you can call the command ` git-partial-clone ` from any directory and use ` TAB ` to autocomplete the CLI options.
27+
28+ # Using the comand line options
29+ Run with the ` --help ` flag to see the complete list of options (recommended). Or read the following sections to clone using the most common options.
30+ ```
31+ $ git-partial-clone -h
32+
33+ Clone a subdirectory of a github/gitlab repository.
34+
35+ USAGE:
36+ git-partial-clone [OPTIONS] ARGUMENTS
37+ git-partial-clone # Or assume config variables in shell.
38+
39+ OPTIONS:
40+ --help Show this manual.
41+
42+ Using a config file:
43+ -f | --file Path to the configuration file.
44+
45+ CLI options (mandatory):
46+ -o | --owner Author (owner) of the repository.
47+ -r | --repo Name of the repository.
48+
49+ CLI options (optional):
50+ -h | --host github (default) or gitlab.
51+ -s | --subdir Subfolder to be cloned.
52+
53+ -t | --token Path to your access token (for private repos).
54+ -u | --user Your username (for private repos).
55+
56+ -b | --branch Branch to be fetched.
57+ -d | --depth Number of commits to be fetched.
58+ ```
59+
60+ ## Clone from public repositories
61+ Provide the mandatory options ` --repo ` , ` --owner ` and the subdirectory (` --subdir ` ) you want to clone.
62+
63+ The following example clones a subfolder of my [ vscode-settings] ( https://github.com/lu0/vscode-settings/tree/master/json/snippets ) repository.
1964``` zsh
20- git-partial-clone --file path/to/your/config/file.conf
65+ git-partial-clone --owner=lu0 --repo=vscode-settings --subdir=json/snippets
2166```
2267
23- # Configuration
68+ You can also clone the entire repository, although this is not the intended use.
69+ ``` zsh
70+ git-partial-clone --owner=lu0 --repo=vscode-settings
71+ ```
72+
73+ ## Clone from private repositories
74+ You will need to generate an access token in order to clone private repositories, as password authentication is deprecated.
75+
76+ - Github: [ github.com/settings/tokens] ( https://github.com/settings/tokens ) .
77+ - Gitlab: [ gitlab.com/-/profile/personal_access_tokens] ( https://gitlab.com/-/profile/personal_access_tokens ) .
78+
79+ Save your token in a file and provide its path with the ` --token ` option, then provide your username with the ` --user ` option.
80+
81+ The following example would clone a subfolder of a private repository.
82+ ``` zsh
83+ git-partial-clone --owner=owner --repo=repo --subdir=path/to/subdir \
84+ --token=/path/to/your/token/file --user=username_with_access
85+ ```
86+
87+ # Using a configuration file
88+ Using a configuration file will give you more control over the objects you're cloning. You can test this functionality with the provided configuration file:
89+ ``` zsh
90+ git-partial-clone --file=example.conf
91+ ```
92+ By the end of the execution, you will see a ` tmp ` directory containing the subfolder of the example repository.
93+
94+ ## Configuration variables
2495Fill in the config file ([ ` template.conf ` ] ( ./template.conf ) ) with the information of the repository you're cloning. You can see the example file [ here] ( ./example.conf ) .
2596
26- ## Mandatory variables
97+ ### Mandatory variables
2798
2899- ` GIT_HOST ` :
29100 - ` github ` if the repository is hosted on Github.
@@ -36,21 +107,13 @@ Fill in the config file ([`template.conf`](./template.conf)) with the informatio
36107 - ** Subdirectory of the repository you want to clone** .
37108 - Omit it to clone the entire repository.
38109
39- ## Mandatory variables for ** private repositories**
40- You will need to generate an access token in order to clone private repositories, as password authentication is deprecated.
41-
42- - Github: [ github.com/settings/tokens] ( https://github.com/settings/tokens ) .
43- - Gitlab: [ gitlab.com/-/profile/personal_access_tokens] ( https://gitlab.com/-/profile/personal_access_tokens ) .
44-
45- Once you have a token, store it in a file.
46-
110+ ### Variables for ** private repositories**
47111- ` TOKEN_PATH ` :
48112 - Path to the file containing the access token.
49113- ` GIT_USER ` :
50114 - Username with access to the repository.
51115
52- ## Optional variables
53- The following variables give you more control over the objects you're cloning.
116+ ### Optional variables
54117- ` BRANCH ` :
55118 - The branch to be fetched.
56119 - Omit it to pull all of the branches and switch to the default one.
0 commit comments