FlutterFever Studio
Back to packages

Gg Git Flutter package guide

Utility scripts for Git repository validation and automation in Flutter projects.

Install command
Copy and run in your Flutter project
flutter pub add gg_git

When to use Gg Git

The **gg_git** package brings a suite of lightweight, pure‑Dart helpers that make common Git‑related tasks effortless inside your Flutter workflow. Whether you need to verify that a repository follows your team's branching policy, ensure that generated files are up‑to‑date, or automate pre‑commit checks, gg_git provides a clear, testable API that can be called from Dart code, CI pipelines, or custom Flutter tooling. By abstracting Git commands into Dart functions, the package eliminates the need for shell scripts, reduces platform‑specific quirks, and keeps your entire development stack in a single language.

**When to use gg_git** Developers often rely on ad‑hoc scripts to enforce repository hygiene, but those scripts can become brittle, hard to maintain, and difficult to integrate with Flutter's testing framework. gg_git shines when you want a programmatic way to query the current HEAD, list changed files, validate commit messages, or confirm that the repository is clean before launching a build. It is especially valuable in CI/CD environments where you need deterministic checks without spawning external processes, and in large teams where consistent repository standards are a must.

**Where it fits in a Flutter architecture** gg_git is a pure utility layer that lives outside of your UI code. It can be placed in a `utils` or `services` folder and injected wherever you need repository information—be it a build script, a custom Flutter command, or a test harness. Because it does not depend on Flutter widgets, it works equally well in pure Dart packages, command‑line tools, and Flutter apps targeting mobile, web, or desktop. This separation keeps your presentation layer clean while giving you a reliable source of truth about the state of the Git repo.

**Setup and quick start** Adding gg_git to a project is a single line: `flutter pub add gg_git`. After the package resolves, import it with `import 'package:gg_git/gg_git.dart';`. The API is intentionally simple: call `GitHelper.isClean()` to check for uncommitted changes, `GitHelper.currentBranch()` to retrieve the active branch name, or `GitHelper.validateCommitMessage(pattern)` to enforce a regex rule. All functions return `Future` objects, making them easy to await in async code or to integrate with test suites. The package also includes a small set of pre‑written scripts for common CI checks, which you can customize or extend.

**Production considerations** While gg_git is safe for development and CI, be mindful that it interacts with the local file system and the Git binary. In production mobile or web builds, the Git repository is typically not bundled, so calls to gg_git will return defaults or throw informative errors. Therefore, guard usage behind environment checks (e.g., `kReleaseMode`) or limit it to tooling that runs on developer machines and CI agents. The package follows semantic versioning, and the current stable release is 4.5.4, which includes bug fixes for Windows path handling and improved error messages for missing Git installations.

**Beginner‑friendly use cases** A new Flutter developer can quickly add a pre‑flight check to their `flutter test` command: ```dart Future<void> main() async { if (!await GitHelper.isClean()) { print('⚠️ Uncommitted changes detected – commit or stash before testing.'); exit(1); } runApp(MyApp()); } ``` This snippet prevents accidental test runs on a dirty codebase, reinforcing good habits early on. Another common scenario is a CI step that validates branch naming conventions: ```dart await GitHelper.validateCommitMessage(r'^feat\/.*'); ``` If the pattern does not match, the script fails, ensuring that every feature branch follows the agreed‑upon prefix.

Overall, gg_git offers a pragmatic bridge between Git’s powerful version‑control capabilities and Dart’s expressive, type‑safe ecosystem. By embedding repository logic directly into your codebase, you gain repeatable, testable, and cross‑platform checks that keep your Flutter projects healthy and compliant.

pre‑commit validation
CI branch naming enforcement
checking repository cleanliness before builds
automating version bump scripts
ensuring generated files are up‑to‑date

Pros

  • pure Dart – no native plugins
  • works across all Flutter platforms
  • simple, async API
  • helps enforce team conventions

Watch outs

  • relies on local Git installation
  • limited usefulness in production apps
  • no UI components

Setup notes

Run `flutter pub add gg_git` to add the package. Then import it with `import 'package:gg_git/gg_git.dart';`. No additional native dependencies are required, but ensure that the Git CLI is available on the host machine for full functionality.

Works with Flutter 3.0 and later. Supports Dart 2.17+. The package is pure Dart and runs on Android, iOS, macOS, Windows, Linux, and web (web returns default values as Git is not available).

import 'package:gg_git/gg_git.dart';

Future<void> main() async {
  final branch = await GitHelper.currentBranch();
  final isClean = await GitHelper.isClean();
  print('Current branch: $branch');
  print('Repository clean: $isClean');

  // Enforce a simple commit‑message rule
  final valid = await GitHelper.validateCommitMessage(r'^feat\/.*');
  if (!valid) {
    print('Commit messages must start with "feat/"');
  }
}

Official package resources