GitHub rọrun lati lo ọpa laini aṣẹ: “gh”!

Ti o ba ti nlo GitHub ati fẹran laini aṣẹ bi emi lati ṣe ohun gbogbo laisi eyikeyi awọn ilolu lori GUI, o le ti ṣe akiyesi bii GitHub ṣe bẹrẹ lati lo ohun elo kii ṣe-tuntun wọn ti a pe ni “gh”. Mo pinnu lati fun ni shot, nitori pe o dabi ẹni ti o ni ileri lẹhin gbogbo. Ati ki o Mo ti tikalararẹ feran o kan Pupo – Ki Elo ti mo fe lati ṣe ohun article nipa o!

Ṣaaju ki a to bẹrẹ botilẹjẹpe, Mo nilo lati ṣalaye ọpọlọpọ awọn ofin Emi yoo lo ninu nkan yii.

"GH" duro fun "GitHub". Eyi ni ibiti orukọ ọpa naa ti wa lati daradara, nitorinaa ko le dapo pẹlu Git funrararẹ. Lati ṣe alaye ohun ti o ṣe ni gbogbogbo, o le ṣẹda, orita, paarẹ, ṣawari awọn ibi ipamọ; ṣẹda awọn ibeere fa; ati ọpọlọpọ awọn siwaju sii. Ni ọran ti o ko ba le rii ẹya kan ṣugbọn tun ko fẹ lati lọ kuro ni ebute, o tun pese aṣawakiri ti o da lori ọrọ fun ọ lati ṣawari awọn oju-iwe ni GitHub.

"CLI" duro fun "Command Lohun Ioju-aye”. Ti Terminal (tabi ni Windows, Command Prompt) jẹ ọkan ninu wọn. Ti “CLI” ba wa lẹgbẹẹ orukọ app kan (“Git CLI” fun nkan yii), o tumọ si pe app naa nṣiṣẹ nipasẹ ebute nikan. Ati "Git CLI" ni aaye yii jẹ, daradara, Git ti a mọ. Bii aṣẹ ti a ṣe awọn adehun tabi awọn atunbere pẹlu.

GUI duro fun "Graphical User Interface” ati pe o jẹ wiwo ti a “lọ kiri” lori. Dara julọ, agbegbe tabili ni gbogbogbo jẹ GUI kan.

“bọtini API” kan jẹ diẹ ninu iru okun aṣiri/faili ti o lo lati jẹri si awọn iṣẹ. Ṣọra pe o fori ijẹrisi ifosiwewe 2 ati bẹbẹ lọ nigbati o ba jẹri pẹlu rẹ. Nitorinaa rii daju pe o tọju wọn lailewu ati ibikan ti ko le de ọdọ nipasẹ awọn ọna miiran.

Ni akọkọ, kini ohun elo yii? Bawo ni o ṣe mu awọn iṣẹ ṣiṣe ti a yoo ṣe nipasẹ Git CLI?

“gh” ni a le gba bi orisun ṣiṣi (Orisun koodu) wrapper ti nlo Git CLI funrararẹ ati awọn API GitHub lati ṣe awọn nkan. Ni otitọ, o le paapaa kọja awọn paramita si awọn aṣẹ Git ti o nlo! Emi yoo gba sinu awọn nigbamii lori.

Fifi sori ẹrọ ati ṣeto

Ranti pe Emi yoo lọ nipasẹ fifi sori ẹrọ ni lilo Termux. Ṣugbọn ilana naa yẹ ki o lẹwa pupọ bi o ṣe le ni lori distro ti o da lori Debian - Ubuntu ni lori awọn ibi ipamọ osise wọn fun apẹẹrẹ. Fun Windows, daradara, o nilo boya CygWin tabi WSL Mo ro pe. ¯ \_(ツ) _/ ¯

# Jẹ ki a fi ẹrọ naa sori ẹrọ ni akọkọ. Paapaa fifi Git sori ẹrọ bi o ṣe jẹ ẹhin # fun gh. $ pkg fi git gh -y # Lẹhinna ṣaaju ohun gbogbo, a nilo lati jẹrisi. Eyi yoo ṣafipamọ bọtini # API tuntun kan sori ibi ipamọ data irinṣẹ nitorinaa iwọ kii yoo nilo lati jẹri # lẹẹkansi. Ti o ba ti ṣeto GITHUB_TOKEN tẹlẹ, eyi kii yoo ṣiṣẹ bẹ yọkuro # akọkọ. :) $ gh auth wiwọle

Ni bayi, ṣaaju ki a to tẹsiwaju nibi, Mo nilo lati tọka si ọpọlọpọ awọn nkan.

  • Ni ibere, maṣe yan “Olupin Idawọlẹ GitHub” ti o ko ba ni diẹ ninu iru GitHub ti o gbalejo.
  • Keji, lo SSH dipo HTTPS ti o ba fi kun bọtini gbogbo eniyan lori akọọlẹ GitHub rẹ. Ni ọran ti o padanu bọtini API, o kere ju kii yoo padanu bọtini SSH rẹ ki o le jẹ ọna isubu ti o dara daradara.
  • Ni ẹkẹta, yan wíwọlé pẹlu ẹrọ aṣawakiri nikan ti o ko ba ni bọtini API ni ọwọ! Lootọ, kii yoo ni oye lati ni bọtini miiran lakoko ti o ti ni ọkan tẹlẹ.

Ni kete ti o ba ti ṣeto awọn nkan soke, jẹ ki a sọ fun Git CLI nipa rẹ.

$ gh auth iṣeto-git

Eyi yoo jẹ ki awọn atunto Git CLI to ṣe pataki ni ọran ti awọn ifasilẹ rẹ ba wọle ati jẹ ki o lo Git dipo GH.

Diẹ ninu awọn aṣẹ ipilẹ

Ni bayi ti o ti ṣeto GH, jẹ ki n kọ ọ ni ọpọlọpọ awọn ofin ipilẹ ni ipilẹ itan kan.

Ni akọkọ, jẹ ki a sọ pe o fẹ ṣẹda ibeere fifa si awọn ifihan agbegbe mi. Ti o fẹ lati orita o akọkọ.

$ gh repo orita windowz414/platform_manifest ! windowz414/platform_manifest ti wa tẹlẹ? Ṣe o fẹ lati ṣe oniye orita naa? Bẹẹni Cloning sinu 'platform_manifest'... latọna jijin: Ṣiṣe awọn nkan: 136, ṣe. latọna jijin: kika ohun: 100% (136/136), ṣe. latọna jijin: funmorawon ohun: 100% (81/81), ṣe. latọna jijin: Total 136 (delta 46), reused 89 (delta 12), pack-reused 0 Ngba ohun: 100% (136/136), 30.70 KiB | 166.00 KiB / s, ṣe. Awọn ipinnu deltas: 100% (46/46), ṣe. Nmu imudojuiwọn lati github.com:windowz414/platform_manifest * [ẹka tuntun] amyrom/rosie -> oke / amyrom/rosie * [ẹka tuntun] aosp-eleven -> oke / aosp- eleven * [ẹka tuntun] aosp-ten -> upstream / aosp-ten * [titun ẹka] itọka-11.0 -> oke / itọka-11.0 * [titun ẹka] cm-14.1 -> oke / cm-14.1 * [titun ẹka] dot11 -> oke / dot11 * [titun ẹka] ] e/os/v1-nougat -> upstream/e/os/v1-nougat * [titun ẹka] ito-11 -> oke / omi-11 * [titun ẹka] fox_7.1 -> oke / fox_7.1 * [ẹka tuntun] hentai-rika -> oke / hentai-rika * [ẹka tuntun] ion-pie -> oke / ion-pie * [ẹka tuntun] idile-15.1 -> oke / iran-15.1 * [ẹka tuntun] idile idile -17.1 -> upstream / lineage-17.1 * [titun ẹka] lineage-18.1 -> upstream / lineage-18.1 * [titun ẹka] lineage-18.1_teos -> upstream / lineage-18.1_teos * [titun ẹka] iran-19.0 - > upstream / lineage-19.0 * [titun ẹka] akọkọ -> oke / akọkọ * [titun ẹka] mkn-mr1 -> oke / mkn-mr1 * [titun ẹka] revengeos-r11.0 -> oke / revengeos-r11.0. 1 * [titun ẹka] stellar-S1 -> oke / stellar-S11 * [titun ẹka] teos-n -> oke / teos-n * [titun ẹka] weebprojekt-11 -> oke / weebprojekt-XNUMX ✓ Cloned orita

Lẹhinna jẹ ki a sọ pe o ni agbari lọtọ fun awọn adanwo rẹ ti a pe ni “wz414-labs”, pe o ko ṣe orita lori profaili ti ara ẹni sibẹsibẹ o fẹ lati oniye nibẹ lẹhinna ṣii ibeere fa nipasẹ nibẹ dipo. O tun fẹ lati ṣe ẹda ẹda “cm-14.1” nitorinaa iwọ kii yoo nilo lati ṣe git-checkout si rẹ lẹẹkansi.

$ gh repo orita windowz414/platform_manifest --org ="wz414-labs" -- --branch ="cm-14.1" ✓ Ṣẹda orita wz414-labs/platform_manifest? Ṣe o fẹ lati ṣe oniye orita naa? Bẹẹni Cloning sinu 'platform_manifest'... latọna jijin: Ṣiṣe awọn nkan: 136, ṣe. latọna jijin: kika ohun: 100% (136/136), ṣe. latọna jijin: funmorawon ohun: 100% (81/81), ṣe. latọna jijin: Total 136 (delta 46), reused 89 (delta 12), pack-reused 0 Ngba ohun: 100% (136/136), 30.70 KiB | 120.00 KiB / s, ṣe. Awọn ipinnu deltas: 100% (46/46), ṣe. Nmu imudojuiwọn lati github.com:windowz414/platform_manifest * [ẹka tuntun] amyrom/rosie -> oke / amyrom/rosie * [ẹka tuntun] aosp-eleven -> oke / aosp- eleven * [ẹka tuntun] aosp-ten -> upstream / aosp-ten * [titun ẹka] itọka-11.0 -> oke / itọka-11.0 * [titun ẹka] cm-14.1 -> oke / cm-14.1 * [titun ẹka] dot11 -> oke / dot11 * [titun ẹka] ] e/os/v1-nougat -> upstream/e/os/v1-nougat * [titun ẹka] ito-11 -> oke / omi-11 * [titun ẹka] fox_7.1 -> oke / fox_7.1 * [ẹka tuntun] hentai-rika -> oke / hentai-rika * [ẹka tuntun] ion-pie -> oke / ion-pie * [ẹka tuntun] idile-15.1 -> oke / iran-15.1 * [ẹka tuntun] idile idile -17.1 -> upstream / lineage-17.1 * [titun ẹka] lineage-18.1 -> upstream / lineage-18.1 * [titun ẹka] lineage-18.1_teos -> upstream / lineage-18.1_teos * [titun ẹka] iran-19.0 - > upstream / lineage-19.0 * [titun ẹka] akọkọ -> oke / akọkọ * [titun ẹka] mkn-mr1 -> oke / mkn-mr1 * [titun ẹka] revengeos-r11.0 -> oke / revengeos-r11.0. 1 * [titun ẹka] stellar-S1 -> oke / stellar-S11 * [titun ẹka] teos-n -> oke / teos-n * [titun ẹka] weebprojekt-11 -> oke / weebprojekt-XNUMX ✓ Cloned orita

O ri Emi ko lo "-b cm-14.1" ati ki o ṣe awọn gun ariyanjiyan dipo. Ni ọjọ ti nkan yii, Kínní 16, 2022, GH ni kokoro kan pe ko kọja awọn ariyanjiyan kukuru si Git CLI ni deede ati nitorinaa o nilo lati ṣee ṣe bi awọn ariyanjiyan gigun dipo.

Ni kete ti iyẹn ba ti ṣe, o tẹ folda nigbagbogbo, ṣe awọn ayipada rẹ, ṣe adehun lẹhinna tẹ, o ti ṣetan lati ṣe ibeere fa. Fun eyi, gbogbo ohun ti o nilo ni rọrun

$ gh pr ṣẹda --branch ="cm-14.1" Ṣiṣẹda ibeere fifa fun wz414-labs: cm-14.1 sinu cm-14.1 ni windowz414/platform_manifest? Teos akọle: Yipada si Git-Polycule? Ara ? Kini atẹle? Fi silẹ https://github.com/windowz414/platform_manifest/pull/1

Ti o ko ba fikun “–ẹka = cm-14.1”, iwọ yoo ṣẹda PR si ọna ẹka “akọkọ”, eyiti yoo fa awọn ọran nigbati ko ba ni ọwọ ni ẹtọ.

Ati ni bayi, Mo nilo lati dapọ PR yii, otun? Nitorinaa MO kọkọ ṣe oniye repo, ṣayẹwo si ẹka ti a yàn, ati ṣe atokọ awọn PRs akọkọ.

# Cloning akọkọ. $ git clone https://github.com/windowz414/platform_manifest Cloning sinu 'platform_manifest'... latọna jijin: Ṣiṣe awọn nkan: 136, ṣe. latọna jijin: kika ohun: 100% (136/136), ṣe. latọna jijin: funmorawon ohun: 100% (81/81), ṣe. latọna jijin: Total 136 (delta 46), reused 89 (delta 12), pack-reused 0 Ngba ohun: 100% (136/136), 30.70 KiB | 137.00 KiB / s, ṣe. Awọn ipinnu deltas: 100% (46/46), ṣe. # Lẹhinna ṣayẹwo si ẹka naa. $ git isanwo cm-14.1 ẹka 'cm-14.1' ti a ṣeto si orin 'ipilẹṣẹ/cm-14.1'. Yipada si ẹka tuntun 'cm-14.1' # Ati ni bayi kikojọ awọn PRs. $ gh pr akojọ Nfihan 1 ti 1 ṣiṣi ibeere fifa ni windowz414/platform_manifest #1 teos: Yipada si Git-Polycule wz414-labs: cm-14.1

Ni bayi ti a rii pe PR wa lati yipada latọna jijin si “Git-Polycule”, jẹ ki a wo kini o yipada pẹlu rẹ.

$ gh pr diff 1 diff --git a/teos.xml b/teos.xml atọka b145fc0..3aadeb6 100644 --- a/teos.xml +++ b/teos.xml @@ -2,7 +2,7, 414 @@ 

O dabi ẹni pe o ni ileri! Akoko lati dapọ!

$gh pr dapọ 1? Ọna idapọ wo ni o fẹ lati lo? Rebase ki o si dapọ? Kini atẹle? Fi silẹ ✓ Tun dapọ ati ibeere fifa ti o dapọ #1 (teos: Yipada si Git-Polycule)

Ni bayi ti Mo dapọ mọ, o le pa orita rẹ rẹ.

$ gh repo paarẹ --jẹrisi wz414-labs/platform_manifest ✓ Ibi ipamọ ti paarẹ wz414-labs/platform_manifest

O rii pe taara paarẹ repo laisi ibeere ijẹrisi nitori pe Mo kọja paramita “–jẹrisi” nibẹ. Ti o ko ba kọja, iwọ yoo gba eyi:

$ gh repo paarẹ windowz414/systemd? Tẹ windowz414/systemd lati jẹrisi piparẹ:

Ati pe iwọ yoo nilo lati tẹ gbogbo orukọ repo naa. Egbin akoko…

Lakotan

Ni irọrun, `gh` jẹ irọrun Git CLI/Curl ti o rọrun ti o ṣopọ awọn iṣẹ Git ti o rọrun ati awọn nkan GitHub API labẹ orule kanna. Bawo ni o ṣe lo? Ṣe o dabi ẹni ti o ni ileri fun ọ bi o ti ṣe si mi? Nreti lati gbọ lati ọdọ rẹ!

Ìwé jẹmọ