lgit 0.9.2

CLI tool for managing git repositories
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
# lgit-rs

[![Rust](https://github.com/Luladjiev/lgit-rs/actions/workflows/rust.yml/badge.svg)](https://github.com/Luladjiev/lgit-rs/actions/workflows/rust.yml)
[![Crates.io](https://img.shields.io/crates/v/lgit.svg)](https://crates.io/crates/lgit)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Downloads](https://img.shields.io/crates/d/lgit.svg)](https://crates.io/crates/lgit)

`lgit-rs` is a powerful, opinionated command-line interface (CLI) tool, designed to simplify the management of git
repositories. It provides a set of commands that streamline common git operations, making your workflow more efficient.

## Table of Contents

- [Features]#features
- [Requirements]#requirements
- [Installation]#installation
- [Quick Start]#quick-start
- [Usage]#usage
- [Configuration]#configuration
- [Why lgit?]#why-lgit
- [Development]#development
- [Contributing]#contributing
- [FAQ & Troubleshooting]#faq--troubleshooting
- [License]#license

## Features

- **Autosquash** (`as`): Automatically squash all fixup commits in the current branch, cleaning up your commit history with interactive rebase. Perfect for consolidating work-in-progress commits.

- **Branch** (`b`): Quickly create a new branch from a freshly pulled BASE branch (defaults to main/master). Ensures you're always branching from the latest code.

- **Checkout** (`co`): Checkout a branch by name with fuzzy matching, or interactively select from a list of all local/remote branches. Supports `--remote` and `--all` flags for filtering.

- **CherryPick** (`cp`): Interactively select and cherry-pick commits from another branch using a fuzzy finder. Makes it easy to apply specific commits across branches.

- **DeleteBranches**: Safely delete all local branches whose remote tracking branches no longer exist. Helps keep your local repository clean.

- **Fixup** (`f`): Commit changes as a fixup commit that can later be automatically squashed with autosquash. Streamlines the process of fixing up previous commits.

- **Rebase** (`r`): Rebase the current branch on top of a freshly pulled BASE branch with a single command. Keeps your feature branches up to date.

- **Git Command Fallback**: For any git command not directly supported by lgit, the tool will automatically pass the command through to git, making lgit a drop-in replacement.

## Requirements

- **Git**: Version 2.0 or higher
- **Rust**: Version 1.70 or higher (if building from source)

You can check your versions:

```bash
git --version
rustc --version  # if building from source
```

## Installation

### Precompiled Binaries (Recommended)

[Download precompiled binaries for Windows, macOS and Linux](https://github.com/Luladjiev/lgit-rs/releases) from the releases page.

### Using Cargo

Installing through Cargo is the easiest way if you have Rust installed:

```bash
cargo install lgit
```

To update to the latest version:
```bash
cargo install lgit
```

### Building from Source

Clone and build the project locally:

```bash
git clone https://github.com/Luladjiev/lgit-rs.git
cd lgit-rs
cargo install --path .
```

### Troubleshooting Installation

**Cargo not found**: Install Rust and Cargo from [rustup.rs](https://rustup.rs/)

**Permission denied**: On macOS/Linux, you might need to add `~/.cargo/bin` to your PATH:
```bash
echo 'export PATH="$HOME/.cargo/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
```

**Old version**: Make sure you're getting the latest version:
```bash
cargo install lgit --force
```

## Quick Start

Here are some common workflows to get you started with lgit:

### Creating and Working on a Feature Branch

```bash
# Create a new feature branch from latest main
lgit branch feature/awesome-feature

# Make your changes, then commit as fixup for easy cleanup later
lgit fixup

# Make more changes, create another fixup
lgit fixup

# Squash all fixup commits when you're ready
lgit autosquash

# Keep your branch up to date with main
lgit rebase
```

### Branch Management

```bash
# Checkout a branch interactively
lgit checkout

# Clean up old branches whose remotes are gone
lgit delete-branches

# Cherry-pick commits from another branch interactively
lgit cherry-pick other-branch
```

### Using Git Commands

```bash
# Any git command works through lgit
lgit status
lgit log --oneline
lgit push origin main

# Explicitly pass commands to git with --
lgit -- branch -d old-feature
```

## Usage

To get a comprehensive list of all available commands and options, you can use the `--help` flag:

```bash
lgit --help
```

Each command has a dedicated help page that can be accessed by running `lgit <command> --help`. For example:

```bash
lgit branch --help
```

### Git Command Fallback

If you run a git command that is not directly supported by lgit, the tool will automatically pass the command through to git. This means you can use lgit as a drop-in replacement for git:

```bash
# These commands will be passed through to git
lgit status
lgit log --oneline
lgit diff HEAD~1
```

You can also explicitly execute git commands by using `--` followed by the git command:

```bash
# Explicitly pass commands to git using --
lgit -- status
lgit -- log --graph --all
lgit -- reset --hard HEAD~1
```

### Command Examples

#### Autosquash
```bash
# Squash all fixup commits in current branch
lgit autosquash

# Squash last 3 commits
lgit as --number 3

# Squash commits since branching from main
lgit as --base main
```

#### Branch Operations
```bash
# Create branch from default base (main/master)
lgit branch my-feature

# Create branch from specific base
lgit b my-feature --base develop

# Interactive checkout
lgit checkout

# Checkout with fuzzy matching
lgit co my-feat  # matches "my-feature"

# List only remote branches
lgit co --remote

# List all branches (local + remote)
lgit co --all
```

#### Fixup Commits
```bash
# Create fixup commit with staged changes
lgit fixup

# Shorthand
lgit f
```

#### Cherry-pick
```bash
# Interactive cherry-pick from another branch
lgit cherry-pick feature/other-branch

# Shorthand
lgit cp main
```

#### Rebase
```bash
# Rebase current branch on freshly pulled main
lgit rebase

# Rebase on specific base branch
lgit r --base develop
```

#### Cleanup
```bash
# Delete branches whose remotes are gone
lgit delete-branches
```

## Configuration

lgit uses your existing git configuration and doesn't require additional setup. However, you can configure some behaviors:

### Default Base Branch

lgit automatically detects your main branch (main, master).

### Git Integration

lgit respects all your existing git configurations including:
- User name and email
- Remote configurations
- Git aliases
- Git hooks

## Why lgit?

lgit streamlines common git workflows by providing opinionated, high-level commands that combine multiple git operations. Here's how lgit compares to standard git commands:

| Task | Git Commands | lgit Command |
|------|-------------|--------------|
| Create branch from latest main | `git checkout main && git pull && git checkout -b feature` | `lgit branch feature` |
| Fixup and squash commits | `git add -A && git commit --fixup=HEAD~1 && git rebase -i --autosquash HEAD~3` | `lgit fixup && lgit autosquash` |
| Interactive branch checkout | `git branch -a` โ†’ copy/paste branch name โ†’ `git checkout branch` | `lgit checkout` |
| Clean up merged branches | `git branch -d branch1 && git branch -d branch2...` | `lgit delete-branches` |
| Rebase on latest main | `git checkout main && git pull && git checkout - && git rebase main` | `lgit rebase` |

### Key Benefits

- **Fewer Commands**: Complex workflows become single commands
- **Interactive Menus**: Fuzzy-finding for branches, commits, and more
- **Smart Defaults**: Automatically detects main branch, pulls latest changes
- **Safety First**: Confirmation prompts for destructive operations
- **Git Compatibility**: Drop-in replacement - all git commands still work
- **Workflow Focused**: Designed around real development workflows, not just git primitives

## Development

`lgit-rs` is developed using the [Rust programming language](https://www.rust-lang.org/) and
the [Cargo package manager](https://doc.rust-lang.org/cargo/).

You can clone the repository
and run the project locally using the following commands:

```bash
git clone https://github.com/luladjiev/lgit-rs.git
cd lgit-rs
cargo run
```

## Contributing

We welcome contributions from the community! Here's how you can help improve lgit:

### Getting Started

1. **Fork the repository** on GitHub
2. **Clone your fork** locally:
   ```bash
   git clone https://github.com/YOUR-USERNAME/lgit-rs.git
   cd lgit-rs
   ```
3. **Create a feature branch**:
   ```bash
   lgit branch feature/your-feature-name
   ```

### Development Workflow

```bash
# Install dependencies and build
cargo build

# Run tests
cargo test

# Run lgit locally during development
cargo run -- --help

# Format code (use rustfmt)
cargo fmt

# Run linting
cargo clippy

# Before submitting, run all checks
cargo test && cargo fmt && cargo clippy
```

### Submitting Changes

1. **Test your changes** thoroughly
2. **Update documentation** if needed
3. **Commit your changes** using conventional commits:
   ```bash
   lgit fixup
   lgit autosquash
   ```
4. **Push to your fork** and **create a Pull Request**

### What to Contribute

- ๐Ÿ› **Bug fixes** - Help us squash bugs!
- โœจ **New features** - Add new git workflow commands
- ๐Ÿ“š **Documentation** - Improve README, add examples
- ๐Ÿงช **Tests** - Increase test coverage
- ๐ŸŽจ **Code quality** - Refactoring, performance improvements

### Project Structure

```
src/
โ”œโ”€โ”€ commands/          # Individual command implementations
โ”‚   โ”œโ”€โ”€ autosquash.rs
โ”‚   โ”œโ”€โ”€ branch.rs
โ”‚   โ””โ”€โ”€ ...
โ”œโ”€โ”€ cli.rs            # Command-line interface definitions
โ”œโ”€โ”€ commands.rs       # Command dispatch logic
โ”œโ”€โ”€ main.rs           # Application entry point
โ””โ”€โ”€ utils.rs          # Shared utilities
```

### Reporting Issues

Found a bug? Have a feature request? [Open an issue](https://github.com/Luladjiev/lgit-rs/issues) with:
- Clear description of the problem or feature
- Steps to reproduce (for bugs)
- Expected vs actual behavior
- Your system info (OS, git version, lgit version)

## FAQ & Troubleshooting

### Common Questions

**Q: Does lgit work with existing git repositories?**
A: Yes! lgit works with any existing git repository. It uses your current git configuration and doesn't modify your repository structure.

**Q: Can I use lgit alongside regular git commands?**
A: Absolutely. lgit is designed as a complement to git, not a replacement. You can mix lgit and git commands freely.

**Q: What happens if I run a git command that lgit doesn't support?**
A: lgit will automatically pass the command through to git, so `lgit status` works the same as `git status`.

**Q: Does lgit support git hooks?**
A: Yes, lgit respects all existing git hooks since it uses git under the hood.

### Troubleshooting

**"Command not found: lgit"**
- Make sure `~/.cargo/bin` is in your PATH
- Try running `cargo install lgit --force` to reinstall

**"Git command failed"**
- Ensure you're in a git repository: `git status`
- Check that git is working: `git --version`
- Verify you have the necessary permissions

**"No base branch found"**
- lgit looks for main or master branches
- Or specify manually: `lgit rebase --base your-branch`

**Interactive menus not working**
- Ensure you're using a compatible terminal
- Try updating to the latest version: `cargo install lgit --force`
- Check that your terminal supports interactive input

**"Branch already exists"**
- Use `lgit checkout existing-branch` to switch to existing branches
- Use `lgit branch new-branch` only for creating new branches

### Compatibility

- **Git Version**: Requires git 2.0+
- **Operating Systems**: Windows, macOS, Linux
- **Terminals**: Works with all major terminal emulators
- **Git Workflows**: Compatible with GitFlow, GitHub Flow, and custom workflows

## License

`lgit-rs` is licensed under the [MIT License](https://choosealicense.com/licenses/mit/), a permissive license that lets
you do anything with the code with proper attribution and without warranty.