LoginSignup
0
0

Git Clone時にすべてのブランチを同期して表示するスクリプト

Last updated at Posted at 2024-04-11
$repoUrl = "リポジトリのURL" # ここにはクローンしたいリポジトリのURLを指定します

# リポジトリをクローンします
git clone $repoUrl

# リポジトリ名を取得します
$repoName = $repoUrl.Split("/")[-1].Replace(".git", "")

# クローンしたディレクトリに移動します
cd $repoName

# リモートリポジトリの全てのブランチを取得します
git fetch --all

# リモートブランチのリストを取得します
$remoteBranches = git branch -r | foreach { $_.trim() -replace "origin/", "" }

# 各リモートブランチに対してローカルブランチを作成します
foreach ($branch in $remoteBranches) {
    git checkout -b $branch origin/$branch
}

# ブランチと最新更新時間を表形式で表示します
$branchInfo = @()
foreach ($branch in $remoteBranches) {
    git checkout $branch
    $lastCommitTime = git log -1 --pretty=format:"%cd" --date=iso
    $branchInfo += New-Object PSObject -Property @{
        Branch = $branch
        LastCommitTime = $lastCommitTime
    }
}
$branchInfo | Format-Table -AutoSize

Gitのブランチ履歴を表形式で表示する

    # リモートブランチのリストを取得します
    $remoteBranches = git branch -r | foreach { $_.trim() -replace "origin/", "" }

    # ブランチと最新更新時間を表形式で表示します
    $branchInfo = @()
    foreach ($branch in $remoteBranches) {
        $lastCommitTime = git show -s --format=%ci origin/$branch
        $branchInfo += New-Object PSObject -Property @{
            Branch = $branch
            LastCommitTime = $lastCommitTime
        }
    }
    $branchInfo | Sort-Object LastCommitTime -Descending | Format-Table -AutoSize
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0