Skip to content

petrgazarov/git-repo-name

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

97 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

git-repo-name

Unit tests

git-repo-name is a CLI tool that syncs your local git directory name with the remote repository name.

It works bi-directionally and supports these two main use cases:

  • When you rename a repo on GitHub, run git-repo-name pull to update the local git directory name.
  • When you rename a local git directory, run git-repo-name push to rename the repo on GitHub.

In both cases, it makes an API call to GitHub, compares the repo name to the local directory name, and automatically renames the appropriate side.

Detailed Usage

git-repo-name provides four main commands:

git-repo-name pull    # Fetches repo name from the remote and renames local git directory name to match it
git-repo-name push    # Renames repo name on the remote with the local git directory name
git-repo-name fetch   # Fetches repo name from the remote without making changes
git-repo-name config  # Configures settings (GitHub token and default remote)

pull

Fetches repo name from the remote and renames local git directory name to match it.

Note: For private GitHub repos, this requires a GitHub PAT (see Configuration Keys for more details).

Examples

# Basic usage
git-repo-name pull

# Specify a remote [default: origin]
git-repo-name pull -r upstream

# Preview what would happen without making changes
git-repo-name pull -n

push

Renames repo name on the remote with the local git directory name.

Note: For GitHub repos, this requires a GitHub PAT (see Configuration Keys for more details).

Examples

# Basic usage
git-repo-name push

# Specify a remote [default: origin]
git-repo-name push -r upstream

# Preview what would happen without making changes
git-repo-name push -n

fetch

Fetches repo name from the remote without making changes.

Examples

# Basic usage
git-repo-name fetch

# Specify a remote [default: origin]
git-repo-name fetch -r upstream

config

Configures settings.

Configuration Keys

  • default-remote: The remote to use when none is specified (defaults to "origin")

    Examples:

    # View default remote
    git-repo-name config default-remote
    
    # Set default remote
    git-repo-name config default-remote upstream
  • github-token: GitHub personal access token for authenticating GitHub API requests.

    Note: See the table below to determine the type of GitHub token you need and the permissions required.

    Scenario PAT type Permissions required
    Public repositories (pull/fetch only) N/A (no token required) None
    Private repositories owned by you Fine-grained Metadata (read) for pull/fetch; Administration (write) for push
    Organization repositories Classic repo scope
    Mixed personal & organization repositories Classic repo scope

    Examples:

    # View GitHub token
    git-repo-name config github-token
    
    # Set GitHub token
    git-repo-name config github-token ghp_your_token_here

Installation

Homebrew (recommended)

  1. Install the git-repo-name formula:

    brew tap petrgazarov/git-repo-name
    brew install git-repo-name
  2. Add the following line to your shell startup file (e.g., ~/.bashrc or ~/.zshrc):

    source "$(brew --prefix)/share/git-repo-name/git-repo-name.sh"

Direct binaries

Pre-compiled binaries are available on the Releases page.

When downloading binaries directly, you'll need to manually set up shell integration:

  1. Download both the binary and the shell script from the releases page

  2. Make both files executable using:

    chmod +x /path/to/git-repo-name-bin /path/to/git-repo-name
  3. Place the binary in your PATH as git-repo-name-bin

  4. Place the shell script in your PATH as git-repo-name

  5. Add the following line to your shell startup file (e.g., ~/.bashrc or ~/.zshrc):

    source "$(which git-repo-name)"

Build from source

Alternatively, you can clone this repository and build from source using Cargo:

  1. Install and build the binary:

    cargo install --git https://github.com/petrgazarov/git-repo-name.git
  2. Rename the cargo-installed binary:

    mv $(which git-repo-name) $(dirname $(which git-repo-name))/git-repo-name-bin
  3. Download the shell script from the repository and make it executable:

    curl -o /usr/local/bin/git-repo-name https://raw.githubusercontent.com/petrgazarov/git-repo-name/main/git-repo-name.sh
    chmod +x /usr/local/bin/git-repo-name

    Replace /usr/local/bin with your preferred installation directory (ensure it's in your PATH).

  4. Add the following line to your shell startup file (e.g., ~/.bashrc or ~/.zshrc):

    source "$(which git-repo-name)"

Supported remotes

git-repo-name currently supports GitHub and file (bare) remotes.

About

CLI tool that syncs your local git directory name with the remote repository name

Topics

Resources

License

Stars

Watchers

Forks