@git-lazy/remote
v2.0.3
Published
@git-lazy/remote
Readme
@git-lazy/remote
Utilities for managing remote Git branches, including renaming capabilities
Installation
npm install @git-lazy/remote
# or
pnpm add @git-lazy/remote
# or
yarn add @git-lazy/remoteUsage
import { renameRemoteBranch } from '@git-lazy/remote';
// 重新命名 origin 上的遠端分支
// Rename a remote branch on origin
const result = renameRemoteBranch('origin', 'feature/old-name', 'feature/new-name');
if (result) {
console.log('分支重新命名成功 / Branch renamed successfully');
}
// 指定工作目錄執行
// Execute with specified working directory
renameRemoteBranch('origin', 'dev', 'develop', {
cwd: '/path/to/git/repo'
});API
renameRemoteBranch(remote, old_name, new_name, options?)
重新命名 Git 遠端分支 / Rename a Git remote branch
此函式透過兩個步驟完成分支重新命名:
- 將舊分支推送到遠端的新分支名稱
- 刪除遠端的舊分支
This function completes branch renaming through two steps:
- Push the old branch to the remote with the new branch name
- Delete the old branch from the remote
Parameters:
remote(string) - 遠端倉庫名稱(例如 'origin')/ Remote repository name (e.g., 'origin')old_name(string) - 原始分支名稱 / Original branch namenew_name(string) - 新的分支名稱 / New branch nameoptions?(IOptions) - 可選配置物件 / Optional configuration objectoptions.cwd?(string) - Git 倉庫的工作目錄路徑,預設為process.cwd()/ Working directory path of the Git repository, defaults toprocess.cwd()
Returns: boolean | undefined - 操作成功時返回 true,參數驗證失敗時返回 undefined / Returns true on success, undefined on validation failure
Example:
import { renameRemoteBranch } from '@git-lazy/remote';
// 基本用法
const result = renameRemoteBranch('origin', 'feature/old', 'feature/new');
// 指定工作目錄
renameRemoteBranch('upstream', 'main', 'master', {
cwd: '/path/to/repo'
});renameRemoteBranch.IOptions
重新命名遠端分支的配置選項介面 / Configuration options interface for renaming remote branch
Properties:
cwd?(string) - Git 倉庫的工作目錄路徑,會自動解析為真實路徑 / Working directory path of the Git repository, resolved to real path automatically
Example:
const options: renameRemoteBranch.IOptions = {
cwd: '/path/to/git/repo'
};
renameRemoteBranch('origin', 'dev', 'develop', options);Dependencies
@git-lazy/util- Git 工具函式庫 / Git utility library@lazy-spawn/stringify- 命令輸出字串化 / Command output stringificationtslib- TypeScript 輔助函式 / TypeScript helpers
License
ISC
