Git Town Documentation
repository·main·Indexed 24 days ago
https://github.com/git-town/git-townA CLI tool that automates Git workflows, focusing on branch management, synchronization, and stacked changes. It supports workflows such as Git Flow, GitHub Flow, GitLab Flow, and trunk-based development, providing specialized support for mono-repos and dependent branch stacks.
What's inside Git Town
- Git Town automates the creation, synchronization, shipping, and cleanup of Git branches. It is compatible with popular workflows such as Git Flow, GitHub Flow, GitLab Flow, and trunk-based development. It also provides specialized support for mono-repos and stacked changes.
Overview of Git Town
mainGit Town is a high-level CLI that provides a reusable implementation of Git workflows. It is designed to replace manual, error-prone Bash scripts with engineered commands for common version control scenarios.
Key capabilities include:
- Creating various branch types.
- Keeping branches in sync.
- Compressing, reviewing, and shipping branches efficiently.
- Support for mono-repos and stacked changes.
Git Town is compatible with several branching models, including:
- GitHub Flow
- Git Flow
- GitLab Flow
- Trunk-based development
- Direct commits to the main branch.
Understand Git Town branch types
mainGit Town categorizes branches into two primary groups: Long-lived (perennial) and Short-lived.
Long-lived branches
Also called perennial branches, these are branches that exist indefinitely (e.g.,
main,master,development). The main branch is a special perennial branch that serves as the default base for cutting and merging short-lived branches.Short-lived branches
Used for active development, these are typically created from and merged back into a perennial branch. They are further categorized by ownership:
Owned by you:
- feature branch: Active work branches that Git Town keeps up to date.
- prototype branch: Early-stage branches not yet ready for a shared remote.
- parked branch: Branches you own but are not actively working on; Git Town does not sync these to reduce noise.
Owned by others:
- contribution branches: Branches owned by others that you are contributing code to (no lifecycle events like sync or ship are performed).
- observed branches: Branches owned by others that you review but do not contribute code to.
Understand the Git Town execution and undo frameworks
mainGit Town operates using an interpreter-based execution model and a snapshot-based undo mechanism to ensure reliability and recoverability.
Execution Framework
Git Town commands are not hard-coded scripts; they are programs composed of Git-related opcodes executed by an interpreter.
- Self-modifying programs: Opcodes can inspect the repository state at runtime and inject new opcodes, allowing the program to adapt to the environment.
- Terminate and Resume: If an operation requires user intervention (e.g., resolving a conflict), the interpreter persists the current runstate to disk and exits. After the user resolves the issue in their shell, restarting Git Town loads the runstate and resumes execution from where it left off.
Undo Framework
To revert changes made by a command, Git Town:
- Compares snapshots of the Git repository from before and after the command execution.
- Determines the specific changes made.
- Generates a new program consisting of opcodes that reverse those changes.
- Executes the reversal program via the interpreter.
Git Town compatibility and team usage
mainCompatibility
Git Town is designed to be compatible with other Git tools and the broader Git ecosystem.
Team Requirements
Your entire team does not need to use Git Town to benefit from it. Even as a solo user, Git Town provides value by automating standard Git commands that are typically required to maintain a tidy repository and keep branches in sync.
Understand Git Town branch types and syncing behavior
mainGit Town uses specific branch types to determine how
git town syncorgit town sync --allbehaves. Each type has unique rules for syncing with parents, tracking branches, and whether the branch can be 'shipped'.branch type description syncing behavior ship mainprimary development branch sync with origin, pull from upstream no perenniallong-lived branch (e.g., develop,staging)sync with origin no featurenormal feature branch sync with parent and tracking branch yes prototypework-in-progress feature sync with parent, don't push to tracking yes parkedinactive feature branch no syncing yes contributionsomeone else's branch, you share changes sync with tracking no observedsomeone else's branch, you don't share changes pull from tracking no Supported Git branching models in Git Town
mainGit Town is designed to be flexible and supports a wide range of branching strategies, including:
- GitHub Flow
- Git Flow
- GitLab Flow
- Trunk-based development
It is also compatible with workflows where commits are made directly to the main branch.
Compare Git Town with git-flow
mainWhile
git-flowis a specialized extension focused on providing opinionated support for the specific Git Flow branching model, Git Town is model-agnostic. Git Town focuses on:- Syncing team work across branches.
- Keeping repositories tidy by cleaning up old branches.
You can use Git Town alongside
git-flowif your workflow requires both.Configure Git Town preferences at different levels
mainGit Town uses a hierarchical configuration system. Settings are applied in the following order of precedence (from lowest to highest):
- Default settings: Built-in defaults.
- System-specific settings: Settings specific to the operating system/environment.
- Environment variables: Overrides all other settings.
- Configuration file: Team-wide settings applied to all users in a repository.
- Git metadata (Global): Developer-specific settings for all repositories on a machine.
- Git metadata (Local): User and repository-specific settings that take precedence over all others.
- CLI flags: The highest priority; overrides everything else.
Understand the Lint cached connectors tool
mainThelint_cached_connectorstool is a linter designed to ensure that cached connectors ininternal/forgeare interchangeable with their uncached counterparts. It verifies that every cached connector implements the exact same interfaces as its corresponding uncached connector.Understand Git Town branch lineage configuration
mainGit Town uses specific configuration entries to track the lineage of branches. These entries follow the pattern
git-town-branch.<branch>.parent=<branch>, where<branch>is the name of the branch and its parent.Note: You do not need to manually manage or edit these entries. Git Town automatically maintains this lineage as it creates and removes feature branches.
Verify connector interface parity with lint_cached_connectors
mainThe linter automates the verification of interface implementations by following these steps:
- Parsing Go source files to identify connector pairs.
- Extracting interface implementations from type check comments (e.g.,
var _ forgedomain.ProposalFinder = apiConnector). - Comparing the interfaces implemented by the cached version against the uncached version.
- Reporting any discrepancies where a cached connector is missing an interface implementation present in the uncached version.