• Stars
    star
    906
  • Rank 50,411 (Top 1.0 %)
  • Language
    Python
  • License
    MIT License
  • Created over 6 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Probably the sharpest git repository organizer & rebase/merge workflow automation tool you've ever seen

git-machete

homebrew formula PyPI package PyPI package monthly downloads Conda package Conda downloads Snap
Read the Docs License: MIT CircleCI codecov

πŸ’ͺ git-machete is a robust tool that simplifies your git workflows.

πŸ¦… The bird's eye view provided by git-machete makes merges/rebases/push/pulls hassle-free even when multiple branches are present in the repository (master/develop, your topic branches, teammate's branches checked out for review, etc.).

🎯 Using this tool, you can maintain small, focused, easy-to-review pull requests with little effort.

πŸ‘ A look at a git machete status gives an instant answer to the questions:

  • What branches are in this repository?
  • What is going to be merged (rebased/pushed/pulled) and to what?

🚜 git machete traverse semi-automatically traverses the branches, helping you effortlessly rebase, merge, push and pull.

git machete discover, status and traverse

πŸ”Œ See also VirtusLab/git-machete-intellij-plugin β€” a port into a plugin for the IntelliJ Platform products, including PyCharm, WebStorm etc.

Install

We provide a couple of alternative ways of installation. See PACKAGES.md for the full list.

Instructions for installing bash, zsh, and fish completion scripts are provided in completion/README.md.

git-machete requires Python >= 3.6. Python 2.x is no longer supported.

Using Homebrew (macOS & most Linux distributions)

brew install git-machete

Using pip with sudo (system-wide install)

You need to have Python and pip installed from system packages.

sudo -H pip install git-machete

Tip: pass an extra -U flag to pip install to upgrade an already installed version.

Using pip without sudo (user-wide install)

You need to have Python and pip installed from system packages.

pip install --user git-machete

Please verify that your PATH variable has ${HOME}/.local/bin/ included.

Tip: pass an extra -U flag to pip install to upgrade an already installed version.

Using conda

conda install -c conda-forge git-machete

Using snap (most Linux distributions)

Tip: check the guide on installing snapd if you don't have Snap support set up yet in your system.

sudo snap install --classic git-machete

It can also be installed via Ubuntu Software (simply search for git-machete).

Note: classic confinement is necessary to ensure access to the editor installed in the system (to edit e.g. .git/machete file or rebase TODO list).

Using apt-get via PPA (Ubuntu)

Tip: run sudo apt-get install -y software-properties-common first if add-apt-repository is not available on your system.

sudo add-apt-repository ppa:virtuslab/git-machete
sudo apt-get update
sudo apt-get install -y python3-git-machete

Using rpm (Fedora/RHEL/CentOS/openSUSE...)

Download the rpm package from the latest release and install either by opening it in your desktop environment or with rpm -i git-machete-*.noarch.rpm.

Using Alpine, Arch, Gentoo & other Linux distro-specific package managers

Check Repology for the available distro-specific packages.

Using Nix (macOS & most Linux distributions)

On macOS and most Linux distributions, you can install via Nix:

nix-channel --add https://nixos.org/channels/nixos-unstable unstable  # if you haven't set up any channels yet
nix-env -i git-machete

Note: since nixos-21.05, git-machete is included in the stable channels as well. The latest released version, however, is generally available in the unstable channel. Stable channels may lag behind; see repology for the current channel-package mapping.


Quick start

Discover the branch layout

cd your-repo/
git machete discover

See and possibly edit the suggested layout of branches. Branch layout is always kept as a .git/machete text file, which can be edited directly or via git machete edit.

See the current repository state

git machete status --list-commits

Green edge means the given branch is in sync with its parent.
Red edge means it is out of sync β€” parent has some commits that the given branch does not have.
Gray edge means that the branch is merged to its parent.

Rebase, reset to remote, push, pull all branches as needed

git machete traverse --fetch --start-from=first-root

Put each branch one by one in sync with its parent and remote tracking branch.

Fast-forward merge a child branch into the current branch

git machete advance

Useful for merging the child branch to the current branch in a linear fashion (without creating a merge commit).

GitHub integration

Check out the given PRs into local branches, also traverse chain of pull requests upwards, adding branches one by one to git-machete and check them out locally as well:

git machete github checkout-prs [--all | --by=<github-login> | --mine | <PR-number-1> ... <PR-number-N>]

Create the PR, using the upstream (parent) branch from .git/machete as the base:

git machete github create-pr [--draft]

Note: for private repositories, a GitHub API token with repo access is required. This will be resolved from the first of:

  1. GITHUB_TOKEN env var.
  2. Contents of the .github-token file in the home directory (~). This file has to be manually created by the user.
  3. Auth token from the current gh configuration.
  4. Auth token from the current hub configuration.

FAQ

I've run git machete discover... but the branch layout I see in .git/machete doesn't exactly match what I expected. Am I doing something wrong?

No! It's all right, discover is based on an (imperfect) heuristic which usually yields branch layout close to what the user would expect. It still might not be perfect and β€” for example β€” declare branches to be children of main/develop instead of each other.

Just run git machete edit to fix the layout manually. If you're working on JetBrains IDEs, you can use git-machete IntelliJ plugin to have branch name completion when editing .git/machete file.

Also, consider git machete github checkout-prs instead of git machete discover if you already have GitHub PRs opened.


Can I use git merge for dealing with stacked PRs?

There are two commonly used ways to put a branch back in sync with its base (parent) branch:

  1. rebase the branch onto its base branch
  2. merge the base branch into the branch

While git-machete supports merging base branch (like main) to update the branch (git machete traverse --merge), this approach works poorly with stacked PRs. You might end up with a very tangled history very quickly, and a non-trivial sequence of git cherry-picks might be needed to restore order.

That is why we recommend using rebase over merge for stacked PRs. However, we still recommend using merge for the narrow case of backporting hotfixes.


Sometimes when I run update or traverse, too many commits are taken into the rebase... how to fix that?

Contrary to the popular misconception, git doesn't have a notion of "commits belonging to a branch". A branch is just a movable reference to a commit.

This makes it hard in general case to determine the range of commits that form the "unique history" of the given branch. There's an entire algorithm in git-machete for determining the fork point of the branch (i.e. the place after which the unique history of the branch starts).

One thing that you can do to help fork-point algorithm in its job, is to not delete local branches instantly after they're merged or discarded. They (or specifically, their reflogs) will be still useful for a while to determine fork points for other branches (and thus, the range of commits taken into rebase).

Also, you can always override fork point for a branch explicitly with git machete fork-point --override-to... command.


Reference

Find the docs at Read the Docs. You can also check git machete help and git machete help <command>.

For the excellent overview for the reasons to use small & stacked PRs, see Ben Congdon's blog post.

Take a look at git-machete reference blog post for a guide on how to use the tool.

The more advanced features like automated traversal, upstream inference and tree discovery are described in the second part of the series.


Git compatibility

git-machete (since version 2.13.0) is compatible with git >= 1.8.0.


Contributions

Contributions are welcome! See contributing guidelines for details. Help would be especially appreciated with Python code style, refactoring and tests β€” so far more focus has been put on features, documentation and automating the distribution.

More Repositories

1

scala-cli

Scala CLI is a command-line tool to interact with the Scala language. It lets you compile, run, test, and package your Scala code (and more!)
Scala
544
star
2

graphbuddy

Graph Buddy helps you to understand the code better
HTML
149
star
3

render

Universal data-driven template for generating textual output, as a static binary and a library
Go
140
star
4

iskra

Typesafe wrapper for Apache Spark DataFrame API
Scala
136
star
5

git-machete-intellij-plugin

Probably the sharpest git repository organizer & rebase/merge workflow automation tool you've ever seen
Java
134
star
6

besom

Besom - a Pulumi SDK for Scala. Also, incidentally, a broom made of twigs tied round a stick. Brooms and besoms are used for protection, to ward off evil spirits, and cleansing of ritual spaces.
Scala
124
star
7

pandas-stubs

Pandas type stubs. Helps you type-check your code.
Python
120
star
8

unicorn

Small Slick library for type-safe id handling
Scala
112
star
9

scala-yaml

Scala
92
star
10

Inkuire

Hoogle-like searches for Scala 3 and Kotlin
Scala
91
star
11

avocADO

Safe compile-time parallelization of for-comprehensions for Scala 3
Scala
87
star
12

jenkins-operator

Kubernetes native Jenkins Operator, moved to https://github.com/jenkinsci/kubernetes-operator
Go
82
star
13

bazel-steward

A bot to keep Bazel dependencies up to date
Kotlin
60
star
14

pretty-stacktraces

Scala
58
star
15

tetrisly-react

Tetrisly offers user-friendly components designed for effortless integration. Plus, it's fully compatible with Tetrisly for Figma with a seamless design and development experience in mind.
TypeScript
41
star
16

crypt

Universal cryptographic tool with AWS KMS, GCP KMS, GnuPG and Azure Key Vault support
Go
33
star
17

infrastructure-as-types

Infrastructure as Types - modern infrastructure declaration and deployment toolkit
Scala
26
star
18

ide-probe

Scala
26
star
19

beholder

Small slick lib for create views on on database
Scala
26
star
20

akka-serialization-helper

Serialization toolbox for Akka messages, events and persistent state that helps achieve compile-time guarantee on serializability. No more errors in the runtime!
Scala
26
star
21

activator-play-advanced-slick

Typesafe Activator template for advanced play-slick project
HTML
20
star
22

kubedrainer

Simple Kubernetes Node Drainer
Go
20
star
23

contextbuddy

Platform documentation
CSS
16
star
24

strapi-plugin-content-manager-extension-hierarchical

strapi-plugin-content-manager-extension-hierarchical
JavaScript
15
star
25

community-build3

Scala
14
star
26

scala-packager

Scala
13
star
27

pekko-serialization-helper

Serialization toolbox for Pekko messages, events and persistent state that helps achieve compile-time guarantee on serializability. No more errors in the runtime!
Scala
13
star
28

using_directives

Java
12
star
29

coursier-m1

A small repo to release coursier using self-hosted Mac M1 runner
Shell
11
star
30

vss

Scala
10
star
31

scg-cli

scg-cli is a CLI tool for Semantic Code Graph analysis
Scala
9
star
32

ReactSphere-reactive-beyond-hype

Repo for presentation on ReactSphere: Reactive beyond hype
HCL
8
star
33

akka-workshop-client

Base code for akka workshop.
Scala
8
star
34

scala-compose

Scala
7
star
35

scala.today

Scala
7
star
36

scala-snippet-checker

TypeScript
6
star
37

codetale

CodeTale - documentation & issue tracking
Dockerfile
6
star
38

genesis

Common sbt settings for sbt-based projects
Scala
5
star
39

pyspark-workshop

HTML
5
star
40

data_lake_navigation_atlas

Code for blogpost Navigation in the data lake using Atlas
Scala
5
star
41

ddd-public-materials

All public materials for community prepared by The DDD guild from Virtuslab
Kotlin
5
star
42

kleisli-examples

Examples from blog post on Kleisli arrows
Scala
5
star
43

tips

CSS
4
star
44

go-extended

Things missing or not belonging in the standard library
Go
3
star
45

mesos-on-vagrant

Just a Vagrant file and Ansible playbook for deploying Mesos cluster for testing
3
star
46

scala-workshop

Scala
3
star
47

talk-scala-akka-play

Introductory talk to Scala, Akka and Play! framework
JavaScript
3
star
48

base-types-kt

Library with common types for Kotlin supporting domain-driven functional programming
Kotlin
3
star
49

Edison-BlinkOnboard

Example Akka system for blinking LED at Intel Edison
Scala
3
star
50

jira-stats

Exports some metrics from jira via REST api - currently calculated dev days per ticket
Go
2
star
51

runscope-agent

Containerized Runscope Agent (Dockerfile)
Makefile
2
star
52

homebrew-cloud

This repository contains a collection of Homebrew formulas.
Ruby
2
star
53

scala-cli-packages

Shell
2
star
54

spark_sql_under_the_hood

Code for blogpost: Spark SQL under the hood
Scala
2
star
55

homebrew-scala-cli

Ruby
1
star
56

scalacamp

ScalaCamp.pl site source code
HTML
1
star
57

homebrew-git-machete

1
star
58

scala-workshop-bootstrap

Shell
1
star
59

gpki

Git Public Key Infrastructure
Python
1
star
60

jenkins-operator-assets

Hosting Jenkins Operator assests like images or CSS files.
CSS
1
star
61

virtusity-workshop-graphql

TypeScript
1
star
62

dokka-site

Kotlin
1
star
63

kibana-rpm-packaging

1
star
64

kubectl-deploy

Simple kubectl plugin for rendering and applying Kubernetes manifests
Go
1
star
65

akka-http-kubernetes.g8

Scala
1
star
66

scala-cli.g8

Scala
1
star
67

homebrew-scala-experimental

Ruby
1
star
68

scg-scala

Scala compiler plugin for Semantic Code Graph generation
Scala
1
star
69

ide-probe-tests

Scala
1
star
70

Ariadne-Bootloader

A little less unfinished TFTP bootloader for Arduino Leonardo Ethernet
Arduino
1
star
71

ScalaTastiesScrapper

Scala
1
star
72

scala3-workshop

Scala
1
star
73

aws-cli

Yet Another Dockerized AWS CLI
Makefile
1
star
74

besom-ask-me

Scala
1
star
75

shuttlecraft

Scala
1
star