# @git-lazy/remote > Utilities for managing remote Git branches, including renaming capabilities ## Installation ```bash npm install @git-lazy/remote # or pnpm add @git-lazy/remote # or yarn add @git-lazy/remote ``` ## Usage ```typescript 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 此函式透過兩個步驟完成分支重新命名: 1. 將舊分支推送到遠端的新分支名稱 2. 刪除遠端的舊分支 This function completes branch renaming through two steps: 1. Push the old branch to the remote with the new branch name 2. Delete the old branch from the remote **Parameters:** - `remote` (string) - 遠端倉庫名稱(例如 'origin')/ Remote repository name (e.g., 'origin') - `old_name` (string) - 原始分支名稱 / Original branch name - `new_name` (string) - 新的分支名稱 / New branch name - `options?` (IOptions) - 可選配置物件 / Optional configuration object - `options.cwd?` (string) - Git 倉庫的工作目錄路徑,預設為 `process.cwd()` / Working directory path of the Git repository, defaults to `process.cwd()` **Returns:** `boolean | undefined` - 操作成功時返回 `true`,參數驗證失敗時返回 `undefined` / Returns `true` on success, `undefined` on validation failure **Example:** ```typescript 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:** ```typescript 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 stringification - `tslib` - TypeScript 輔助函式 / TypeScript helpers ## License ISC