Get the FREE Ultimate OpenClaw Setup Guide →

gh-default-branch

npx machina-cli add skill puku0x/agent-skills-test/gh-default-branch --openclaw
Files (1)
SKILL.md
1.1 KB

Get Default Branch

Overview

This skill retrieves the default branch name of the current Git repository using the GitHub CLI command gh repo view --json defaultBranchRef --jq .defaultBranchRef.name.

When to Use

Use this skill when:

  • The user requests the default branch name of the repository.
  • Performing git operations that require knowledge of the default branch (e.g., creating pull requests, comparing branches, checking out the base branch).

Instructions

To get the default branch name, run the command:

gh repo view --json defaultBranchRef --jq .defaultBranchRef.name

The command will output the default branch name (e.g., main, master, develop).

Source

git clone https://github.com/puku0x/agent-skills-test/blob/main/.github/skills/gh-default-branch/SKILL.mdView on GitHub

Overview

This skill retrieves the default branch name of the current Git repository using the GitHub CLI command gh repo view --json defaultBranchRef --jq .defaultBranchRef.name. It returns common defaults such as main, master, or develop, enabling downstream git operations.

How This Skill Works

It calls gh repo view with the JSON query defaultBranchRef and extracts the .defaultBranchRef.name value. The resulting branch name can be used in scripts, PRs, and branch comparisons.

When to Use It

  • You need to know the repository's default branch name for PRs or merges
  • Preparing a script that checks out the base branch before tests or deployments
  • Displaying or logging the base branch in reports or dashboards
  • Performing a comparison between a feature branch and the default branch
  • Resolving which branch to target when creating a new PR or issue

Quick Start

  1. Step 1: Open a terminal in your repository and ensure gh is installed and authenticated
  2. Step 2: Run gh repo view --json defaultBranchRef --jq .defaultBranchRef.name
  3. Step 3: Use the output value in your scripts or git commands, for example to checkout or base a PR

Best Practices

  • Ensure you are in the correct repository directory before running gh commands
  • Authenticate gh and have access to the repository
  • Use the --jq option to extract only the branch name
  • Validate output and handle errors if the repository lacks a default branch or gh fails
  • Cache or reuse the value when possible to reduce CLI calls

Example Use Cases

  • Script prints the default branch to log during setup
  • CI job checks out the default branch before running tests
  • PR automation uses the default branch as the base for PRs
  • A deployment script merges changes into the default branch
  • A dashboard shows the current default branch for multiple repos

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers