# GitHub



### Cloner juste un sous-dossier d'un repo:

```bash
~/Documents                                                                                   $ git init vegas

~/Documents                                                                                   
$ cd vegas
drwxr-xr-x@    - bruno staff 17 nov 16:14  17 nov 16:14  -I  .git/

~/Documents/vegas master                                                                       
$ git remote add origin https://github.com/jaysalvat/vegas.git

~/Documents/vegas master                                                                       
$ git config core.sparsecheckout true

~/Documents/vegas master                                                                       
$ echo "dist/*" >> .git/info/sparse-checkout

~/Documents/vegas master                                                                       
$ git pull --depth=1 origin master
remote: Enumerating objects: 56, done.
remote: Counting objects: 100% (56/56), done.
remote: Compressing objects: 100% (41/41), done.
remote: Total 56 (delta 16), reused 39 (delta 14), pack-reused 0
Dépaquetage des objets: 100% (56/56), 89.72 Kio | 1.91 Mio/s, fait.
Depuis https://github.com/jaysalvat/vegas
 * branch            master     -> FETCH_HEAD
 * [nouvelle branche] master     -> origin/master

```



### Récupérer un sous-dossier d'un repo:

```bash
$ svn export --force https://github.com/jaysalvat/vegas/trunk/dist
```



### Télécharger la dernière release:

```bash
$ wget -O vegas.zip https://github.com/jaysalvat/vegas/archive/refs/heads/master.zip
```



Dernier tag d'un repo:

```bash
$ curl -s 'https://github.com/go-gitea/gitea/tags/'|grep -Eo "$Version v[0-9]{1,2}.[0-9]{1,2}.[0-9]{1,2}"|sort -r|head -n1
 v1.22.0
 
$ curl -s -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/go-gitea/gitea/tags | jq -r '.[0].name'
v1.22.0-dev

```

Récupérer tous les tags d'un repo:

```bash
$ curl -s -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/go-gitea/gitea/tags | jq -r '.'
[
  {
    "name": "v1.22.0-dev",
    "zipball_url": "https://api.github.com/repos/go-gitea/gitea/zipball/refs/tags/v1.22.0-dev",
    "tarball_url": "https://api.github.com/repos/go-gitea/gitea/tarball/refs/tags/v1.22.0-dev",
    "commit": {
      "sha": "d7f73a1334ab7a97d4e055b7c58cdd9ac303f77a",
      "url": "https://api.github.com/repos/go-gitea/gitea/commits/d7f73a1334ab7a97d4e055b7c58cdd9ac303f77a"
    },
    "node_id": "MDM6UmVmNzI0OTU1Nzk6cmVmcy90YWdzL3YxLjIyLjAtZGV2"
  },

```



```
$ curl -s -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/go-gitea/gitea/releases/latest | jq -r '.'
```



#### Repo privé

Sur Github.com, aller dans Réglages -> Personal access tokens

Créer un tokens (classic) avec repo, admin:org,admin:public_key,admin:repo_hook,admin:org_hook

```bash
$ curl -H 'Authorization: token ghp_xxx' \
-H 'Accept: application/vnd.github.v3.raw' \
-O \
-L https://api.github.com/repos/Bruno21/bashbirds/contents/bashbirds.sh
```

```bash
$ curl https://x-access-token:ghp_xxx@raw.githubusercontent.com/Bruno21/bashbirds/main/bashbirds.sh
```



### GitHub CLI

https://docs.github.com/en/github-cli/github-cli/quickstart

```bash
❯ gh auth login
? What account do you want to log into? GitHub.com
? What is your preferred protocol for Git operations on this host? SSH
? Upload your SSH public key to your GitHub account? /Users/bruno/.ssh/id_rsa.pub
? Title for your SSH key: GitHub CLI
? How would you like to authenticate GitHub CLI? Login with a web browser

! First copy your one-time code: 2A9B-F28C
Press Enter to open github.com in your browser...

✓ Authentication complete.
- gh config set -h github.com git_protocol ssh
✓ Configured git protocol
✓ Uploaded the SSH key to your GitHub account: /Users/bruno/.ssh/id_rsa.pub
✓ Logged in as Bruno21

```

#### Créer un repo sur Github.com:

```bash
$ gh repo create Bruno21/bashbirds --private
✓ Created repository Bruno21/bashbirds on GitHub
  https://github.com/Bruno21/bashbirds
```

#### Créer un repo sur Github.com (mode interactif):

Push an existing local repository to GitHub

```bash
$ gh repo create
? What would you like to do? Push an existing local repository to GitHub
? Path to local repository .
? Repository name bashbirds
? Description
? Visibility Private
✓ Created repository Bruno21/bashbirds on GitHub
  https://github.com/Bruno21/bashbirds
? Add a remote? Yes
? What should the new remote be called? github
✓ Added remote git@github.com:Bruno21/bashbirds.git
? Would you like to push commits from the current branch to "github"? Yes
The authenticity of host 'github.com (140.82.121.4)' can't be established.
ED25519 key fingerprint is SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'github.com' (ED25519) to the list of known hosts.
Énumération des objets: 13, fait.
Décompte des objets: 100% (13/13), fait.
Compression par delta en utilisant jusqu'à 8 fils d'exécution
Compression des objets: 100% (13/13), fait.
Écriture des objets: 100% (13/13), 80.34 Kio | 5.36 Mio/s, fait.
Total 13 (delta 5), réutilisés 0 (delta 0), réutilisés du paquet 0 (depuis 0)
remote: Resolving deltas: 100% (5/5), done.
To github.com:Bruno21/bashbirds.git
 * [new branch]      HEAD -> plus
la branche 'plus' est paramétrée pour suivre 'github/plus'.
✓ Pushed commits to git@github.com:Bruno21/bashbirds.git

```

