背景
每天的開(kāi)發(fā)中,我們都會(huì)進(jìn)行不少的合并請(qǐng)求,通常的路徑是:打開(kāi)瀏覽器 -> 訪問(wèn)私有的gitlab服務(wù)器 -> 選擇項(xiàng)目 -> 訪問(wèn)合并請(qǐng)求的頁(yè)面 -> 點(diǎn)擊創(chuàng)建新的合并請(qǐng)求 -> 選擇源分支和目標(biāo)分支 -> 點(diǎn)擊提交 -> 輸入標(biāo)題和內(nèi)容 -> 點(diǎn)擊創(chuàng)建合并請(qǐng)求按鈕。整個(gè)過(guò)程是如此的冗長(zhǎng),我們也可以通過(guò)創(chuàng)建書(shū)簽,減少一些步驟,但我覺(jué)得還是太冗長(zhǎng)了,就在想是否有這樣的工具,幫我做這件事?幸運(yùn)的是有且開(kāi)源??,主角登場(chǎng)>>>
簡(jiǎn)介
glab 是 Gitlab 終端操作軟件,支持的命令包括但不限于創(chuàng)建合并請(qǐng)求等,極大的提升了Gitlab交互效率
安裝
MacOS
使用 Homebrew, 或者直接下載EXE文件
$ brew install glab
Windows
WinGet
$ winget install glab
Scoop
$ scoop install glab
Exe
https://github.com/profclems/glab/releases
其他
https://github.com/profclems/glab#installation
使用
$ glab <command> <subcommand> [flags]
1.登錄你的gitlab站點(diǎn),創(chuàng)建token
通常地址為: https://your_gitlab.com/-/profile/personal_access_tokens ,創(chuàng)建一個(gè)token,賦予 api 和 write_repository 權(quán)限
2.授權(quán)
執(zhí)行 glab auth login 授權(quán)你的 GitLab 賬戶
1. 選擇 gitlab 站點(diǎn),私有還是官方網(wǎng)站
? What GitLab instance do you want to log into? [Use arrows to move, type to filter]
gitlab.com
> GitLab Self-hosted Instance # 私有部署的 gitlab
2. 輸入提供 `web` 的服務(wù)域名
? GitLab hostname: your_gitlab.com # 輸入你的gitlab網(wǎng)站host,如: your_gitlab.com
3. 輸入 `API` 域名
? API hostname: your_gitlab.com
4. 輸入上面剛剛獲取的 `Token`
? Paste your authentication token: lab_dajsldjlasjdl
5. 選擇默認(rèn)協(xié)議
? Choose default git protocol [Use arrows to move, type to filter]
SSH
> HTTPS
HTTP
6. 是否授權(quán)
? Authenticate Git with your GitLab credentials? (Y/n) Y
7. 選擇 `API` 協(xié)議
? Choose host API protocol [Use arrows to move, type to filter]
> HTTPS
HTTP
8. 輸出下面內(nèi)容,表示成功了
- glab config set -h your_gitlab.com git_protocol https
? Configured git protocol
- glab config set -h your_gitlab.com api_protocol https
? Configured API protocol
? Logged in as yourname
核心命令
glab mr [list, create, close, reopen, delete, ...]glab issue [list, create, close, reopen, delete, ...]glab pipeline [list, delete, ci status, ci view, ...]glab releaseglab repoglab labelglab alias
使用示例
$ glab auth login --stdin < token.txt
$ glab issue list
$ glab mr for 123 # Create merge request for issue 123
$ glab mr checkout 243
$ glab pipeline ci view
$ glab mr view
$ glab mr approve
$ glab mr merge
常用命令
# 使用當(dāng)前分支,創(chuàng)建一個(gè)合并請(qǐng)求
$ glab mr create -f test/release/master(默認(rèn),也可以不輸入)