# GitHub Cloner

🚀 Interactive CLI tool for effortlessly cloning your GitHub repositories and managing branches

## Features

- 📋 Interactive list of all your GitHub repositories
- 🔍 Smart organization by users and organizations
- 🎯 Branch management within git repositories:
  - View and checkout branches from open PRs
  - Browse and checkout remote branches
  - Auto-detect existing branches
  - Pull latest changes for local branches
- 🔎 Quick search functionality with autocomplete
- ⚡ Clone repositories directly to your current directory
- 🎯 Duplicate detection to prevent accidental re-cloning
- ⚙️ Configurable sorting options (by name or last update)

## Installation

```bash
npm install -g @relbns/github-cloner
```

## Prerequisites

- Node.js >=18.0.0
- npm >=9.5.1
- GitHub account with a personal access token

### Setting up GitHub Token

1. Create a GitHub personal access token:

   - Go to GitHub Settings → Developer Settings → Personal Access Tokens
   - Generate new token with `repo` scope
   - [GitHub's guide on creating tokens](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens)

2. Add token to your shell profile:

   ```bash
   # For bash users (in ~/.bashrc or ~/.bash_profile):
   export GITHUB_TOKEN=your_token_here

   # For zsh users (in ~/.zshrc):
   export GITHUB_TOKEN=your_token_here
   ```

3. Reload your shell or run:
   ```bash
   source ~/.bashrc  # or ~/.zshrc for zsh users
   ```

## Usage

Simply run:

```bash
clone
```

### Repository Cloning

When run in a non-git directory:

1. Displays an interactive menu of your repositories
2. Allows you to search and select a repository
3. Clones the selected repository to your current directory

### Branch Management

When run inside a git repository:

1. Choose between:
   - Browse branches from open PRs
   - Browse all remote branches
   - Clone a new repository
2. For PR branches:
   - View all branches with open PRs
   - See which branches exist locally
   - Pull latest changes for existing branches
3. For remote branches:
   - View branches that don't exist locally
   - Easily checkout new branches

### Navigation

- Use ↑/↓ arrows to navigate
- Start typing to search repositories
- Press Enter to select
- Choose "Go back" to return to previous menu
- Choose "Exit" to quit

### Settings

Access settings menu to:

- Configure sorting preferences
- Adjust display options
- Manage GitHub token

## Support

For bugs and feature requests, please [open an issue](https://github.com/relbns/github-cloner/issues).

## License

MIT © [Ariel Benesh](https://github.com/relbns)
