An open API service indexing awesome lists of open source software.

https://github.com/belaytzev/git-scoper

Automatically apply git `user.name` and `user.email` to every repository in a directory β€” so you never commit with the wrong identity again.
https://github.com/belaytzev/git-scoper

git gitconfig

Last synced: 3 months ago
JSON representation

Automatically apply git `user.name` and `user.email` to every repository in a directory β€” so you never commit with the wrong identity again.

Awesome Lists containing this project

README

          


git-scoper logo

git-scoper

> 🎯 Automatically apply git `user.name` and `user.email` to every repository in a directory β€” so you never commit with the wrong identity again.

[![GitHub release](https://img.shields.io/github/v/release/belaytzev/git-scoper?style=flat-square)](https://github.com/belaytzev/git-scoper/releases)
[![Go Version](https://img.shields.io/badge/Go-1.21+-00ADD8?style=flat-square&logo=go)](https://go.dev)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square)](https://opensource.org/licenses/MIT)
[![CI](https://img.shields.io/github/actions/workflow/status/belaytzev/git-scoper/ci.yml?style=flat-square&label=CI)](https://github.com/belaytzev/git-scoper/actions)
[![Homebrew](https://img.shields.io/badge/Homebrew-tap-FBB040?style=flat-square&logo=homebrew)](https://github.com/belaytzev/homebrew-tap)

---

## πŸ“– Table of Contents

- [✨ Why git-scoper?](#-why-git-scoper)
- [πŸš€ Quick Start](#-quick-start)
- [πŸ“¦ Installation](#-installation)
- [πŸ› οΈ Usage](#️-usage)
- [βš™οΈ Configuration](#️-configuration)
- [πŸ”„ How It Works](#-how-it-works)
- [πŸ“‹ Output](#-output)
- [πŸ’‘ Example](#-example)
- [🚦 Exit Codes](#-exit-codes)
- [🀝 Contributing](#-contributing)
- [πŸ“„ License](#-license)

---

## ✨ Why git-scoper?

Ever committed code with your **personal email** on a **work repo**? Or vice versa? 😬

Managing git identities across dozens of repositories is tedious and error-prone. **git-scoper** fixes that in one command.

- 🏷️ **Scope your identity** β€” Apply `user.name` and `user.email` to every repo under a directory
- ⚑ **Fast & parallel** β€” Scans directories concurrently with configurable worker count
- 🧠 **Smart config resolution** β€” Reads from a local `gitconfig` file or falls back to `~/.gitconfig`
- πŸ“‚ **Depth control** β€” Configure how deep to scan for nested repositories
- πŸ”’ **Safe by default** β€” Never silently ignores bad config; exits with clear errors
- 🍺 **Easy install** β€” Available via Homebrew or `go install`

---

## πŸš€ Quick Start

```bash
# Install via Homebrew
brew tap belaytzev/tap && brew install git-scoper

# Create a config file in your work directory
echo -e "name=Jane Doe\nemail=jane@acme.com" > ~/Work/gitconfig

# Apply git identity to all repos under ~/Work
git-scoper ~/Work
```

That's it! πŸŽ‰ Every git repository under `~/Work` now has the correct identity configured.

---

## πŸ“¦ Installation

### 🍺 Homebrew (macOS / Linux)

```bash
brew tap belaytzev/tap
brew install git-scoper
```

### πŸ”§ From Source

Requires Go 1.21+:

```bash
go install github.com/belaytzev/git-scoper@latest
```

### πŸ“‹ Prerequisites

- `git` must be installed and available on `PATH`

---

## πŸ› οΈ Usage

```
git-scoper [flags] [base-dir]
```

| Flag | Default | Description |
|------|---------|-------------|
| `--depth` | `2` | πŸ“ Max directory depth to scan, relative to `base-dir` (depth 1 = immediate children only, depth 2 = one level deeper) |
| `--workers` | `4` | πŸ”€ Parallel workers (must be β‰₯ 1) |

- If `base-dir` is omitted, the current directory is used.
- If `base-dir` is itself a git repository, config is applied directly to it and no subdirectory scanning occurs.

---

## βš™οΈ Configuration

git-scoper reads configuration from the following sources (in priority order):

### 1️⃣ Local config: `/gitconfig`

A simple key=value format:

```
name=Jane Doe
email=jane@example.com
```

> ⚠️ If this file exists but is missing `name=` or `email=`, the tool exits with an error. If the file exists but cannot be accessed (e.g. permission denied) or is a directory, the tool exits with an error rather than falling back to `~/.gitconfig`.

### 2️⃣ Global config: `~/.gitconfig`

Standard git INI format β€” reads the `[user]` section.

---

## πŸ”„ How It Works

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ git-scoper β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ β”‚
β”‚ 1. πŸ“– Read Config β”‚
β”‚ └─ /gitconfig ──or── ~/.gitconfig β”‚
β”‚ β”‚
β”‚ 2. πŸ” Scan Directory β”‚
β”‚ └─ Walk up to --depth levels β”‚
β”‚ looking for .git/ directories β”‚
β”‚ β”‚
β”‚ 3. ⚑ Apply in Parallel β”‚
β”‚ └─ N workers run `git config user.name` β”‚
β”‚ and `git config user.email` concurrently β”‚
β”‚ β”‚
β”‚ 4. πŸ“Š Report Results β”‚
β”‚ └─ Updated βœ… β”‚ Failed ❌ β”‚ Skipped ⏭️ β”‚
β”‚ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

---

## πŸ“‹ Output

Each scanned path appears as one of:

| Status | Meaning |
|--------|---------|
| βœ… `Updated: ` | Git config was applied successfully |
| ❌ `Failed: ()` | Git config could not be applied (e.g. not a writable repo) |
| ⏭️ `Skipped: ` | Direct child of `base-dir` that contains no git repository within the scan depth |

> πŸ“ Directories that cannot be read during scanning are silently ignored and do not appear in any output line.

---

## πŸ’‘ Example

```
$ git-scoper /Work/Acme
Config: name=Jane Doe, email=jane@acme.com
Scanning: /Work/Acme (depth 2)
------------------------
Updated: ProjectAlpha
Updated: tools/ProjectBeta
Failed: tools/ReadOnly (git config user.name failed: exit status 128)
Skipped: docs
------------------------
Done. 2 updated, 1 failed, 1 skipped.
```

---

## 🚦 Exit Codes

| Code | Meaning |
|------|---------|
| `0` βœ… | All repos updated successfully |
| `1` ❌ | Any failure: invalid flag values (`--depth` or `--workers` less than 1), `base-dir` does not exist or is not a directory, no config found, scan error, or one or more repos reported `Failed:` |

> πŸ’‘ **Tip**: Check individual `Failed:` lines for per-repo error details.

---

## 🀝 Contributing

Contributions are welcome! πŸŽ‰

1. 🍴 Fork the repository
2. 🌿 Create your feature branch (`git checkout -b feature/amazing-feature`)
3. πŸ’Ύ Commit your changes (`git commit -m 'Add amazing feature'`)
4. πŸ“€ Push to the branch (`git push origin feature/amazing-feature`)
5. πŸ”ƒ Open a Pull Request

Please make sure your code passes CI checks before submitting.

---

## πŸ“„ License

MIT Β© [Alexey Belaytzev](https://github.com/belaytzev)

See [LICENSE](LICENSE) for details.

---


Made with ❀️ for developers who juggle multiple git identities