%global _empty_manifest_terminate_build 0
Name: python-git-machete
Version: 3.17.4
Release: 1
Summary: Probably the sharpest git repository organizer & rebase/merge workflow automation tool you've ever seen
License: MIT
URL: https://github.com/VirtusLab/git-machete
Source0: https://mirrors.nju.edu.cn/pypi/web/packages/cf/f0/54e2a7475144ac4ac5541a58fd1349be5038e5c5ef9105624cfad72c389b/git-machete-3.17.4.tar.gz
BuildArch: noarch
%description
# git-machete
[![homebrew formula](https://img.shields.io/homebrew/v/git-machete)](https://formulae.brew.sh/formula/git-machete)
[![PyPI package](https://img.shields.io/pypi/v/git-machete.svg)](https://pypi.org/project/git-machete)
[![PyPI package monthly downloads](https://img.shields.io/pypi/dm/git-machete.svg)](https://pypistats.org/packages/git-machete)
[![Conda package](https://img.shields.io/conda/vn/conda-forge/git-machete.svg)](https://anaconda.org/conda-forge/git-machete)
[![Conda downloads](https://img.shields.io/conda/dn/conda-forge/git-machete.svg)](https://anaconda.org/conda-forge/git-machete)
[![Snap](https://snapcraft.io/git-machete/badge.svg)](https://snapcraft.io/git-machete)
[![Read the Docs](https://readthedocs.org/projects/git-machete/badge/?version=latest)](https://git-machete.readthedocs.io/en/stable)
[![License: MIT](https://img.shields.io/github/license/VirtusLab/git-machete)](https://github.com/VirtusLab/git-machete/blob/master/LICENSE)
[![CircleCI](https://circleci.com/gh/VirtusLab/git-machete/tree/master.svg?style=shield)](https://app.circleci.com/pipelines/github/VirtusLab/git-machete?branch=master)
[![codecov](https://codecov.io/gh/VirtusLab/git-machete/branch/master/graph/badge.svg)](https://codecov.io/gh/VirtusLab/git-machete)
[//]: # (The image is referenced by its full URL to ensure it renders correctly on https://pypi.org/project/git-machete/)
💪 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.
[//]: # (The image is referenced by its full URL to ensure it renders correctly on https://pypi.org/project/git-machete/)
🔌 See also [VirtusLab/git-machete-intellij-plugin](https://github.com/VirtusLab/git-machete-intellij-plugin#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.
**Instructions for installing bash, zsh, and fish completion scripts are provided in [completion/README.md](completion/README.md).**
git-machete requires Python >= 3.6. Python 2.x is no longer supported.
### Using Homebrew (macOS & most Linux distributions)
```shell script
brew install git-machete
```
### Using snap (most Linux distributions)
**Tip:** check the [guide on installing snapd](https://snapcraft.io/docs/installing-snapd) if you don't have Snap support set up yet in your system.
```shell script
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.
```shell script
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](https://github.com/VirtusLab/git-machete/releases/latest)
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](https://repology.org/project/git-machete/versions) for the available distro-specific packages.
### Using Nix (macOS & most Linux distributions)
On macOS and most Linux distributions, you can install via [Nix](https://nixos.org/nix):
```shell script
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](https://repology.org/project/git-machete/versions) for the current channel-package mapping.
### Using pip with sudo (system-wide install)
You need to have Python and `pip` installed from system packages.
```shell script
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.
```shell script
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
```shell script
conda install -c conda-forge git-machete
```
## Quick start
### Discover the branch layout
```shell script
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
```shell script
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
```shell script
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
```shell script
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:
```shell script
git machete github checkout-prs [--all | --by= | --mine | ... ]
```
Create the PR, using the upstream (parent) branch from `.git/machete` as the base:
```shell script
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`](https://cli.github.com/) configuration.
4. Auth token from the current [`hub`](https://github.com/github/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?
[//]: # (For how to find Medium header anchors, see https://www.freecodecamp.org/news/how-to-link-to-a-specific-paragraph-in-your-medium-article-2018-table-of-contents-method-e66595fea549/)
No! It's all right, `discover` is based on an (imperfect)
[heuristic](https://medium.com/virtuslab/git-machete-strikes-again-traverse-the-git-rebase-jungle-even-faster-with-v2-0-f43ebaf8abb0#0544)
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`](https://git-machete.readthedocs.io/en/stable/#edit) to fix the layout manually.
If you're working on JetBrains IDEs, you can use [git-machete IntelliJ plugin](https://github.com/VirtusLab/git-machete-intellij-plugin#git-machete-intellij-plugin)
to have branch name completion when editing `.git/machete` file.
Also, consider [`git machete github checkout-prs`](#github-integration) 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`](https://git-machete.readthedocs.io/en/stable/#traverse)),
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-pick`s 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](https://slides.com/plipski/git-machete/#/11).
#### 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"](https://git-scm.com/book/en/v2/Git-Branching-Branches-in-a-Nutshell).
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_](https://medium.com/virtuslab/make-your-way-through-the-git-rebase-jungle-with-git-machete-e2ed4dbacd02#1ac9)
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](https://virtuslab.github.io/tips/#git/git-reflog)) 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...`](https://git-machete.readthedocs.io/#fork-point) command.
## Reference
Find the docs at [Read the Docs](https://git-machete.readthedocs.io/).
You can also check `git machete help` and `git machete help `.
For the excellent overview for the reasons to use small & stacked PRs,
see [Ben Congdon](https://github.com/bcongdon)'s [blog post](https://benjamincongdon.me/blog/2022/07/17/In-Praise-of-Stacked-PRs/).
Take a look at git-machete
[reference blog post](https://medium.com/virtuslab/make-your-way-through-the-git-rebase-jungle-with-git-machete-e2ed4dbacd02)
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](https://medium.com/virtuslab/git-machete-strikes-again-traverse-the-git-rebase-jungle-even-faster-with-v2-0-f43ebaf8abb0).
## Git compatibility
git-machete (since version 2.13.0) is compatible with git >= 1.8.0.
## Contributions
Contributions are welcome! See [contributing guidelines](CONTRIBUTING.md) 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.
%package -n python3-git-machete
Summary: Probably the sharpest git repository organizer & rebase/merge workflow automation tool you've ever seen
Provides: python-git-machete
BuildRequires: python3-devel
BuildRequires: python3-setuptools
BuildRequires: python3-pip
%description -n python3-git-machete
# git-machete
[![homebrew formula](https://img.shields.io/homebrew/v/git-machete)](https://formulae.brew.sh/formula/git-machete)
[![PyPI package](https://img.shields.io/pypi/v/git-machete.svg)](https://pypi.org/project/git-machete)
[![PyPI package monthly downloads](https://img.shields.io/pypi/dm/git-machete.svg)](https://pypistats.org/packages/git-machete)
[![Conda package](https://img.shields.io/conda/vn/conda-forge/git-machete.svg)](https://anaconda.org/conda-forge/git-machete)
[![Conda downloads](https://img.shields.io/conda/dn/conda-forge/git-machete.svg)](https://anaconda.org/conda-forge/git-machete)
[![Snap](https://snapcraft.io/git-machete/badge.svg)](https://snapcraft.io/git-machete)
[![Read the Docs](https://readthedocs.org/projects/git-machete/badge/?version=latest)](https://git-machete.readthedocs.io/en/stable)
[![License: MIT](https://img.shields.io/github/license/VirtusLab/git-machete)](https://github.com/VirtusLab/git-machete/blob/master/LICENSE)
[![CircleCI](https://circleci.com/gh/VirtusLab/git-machete/tree/master.svg?style=shield)](https://app.circleci.com/pipelines/github/VirtusLab/git-machete?branch=master)
[![codecov](https://codecov.io/gh/VirtusLab/git-machete/branch/master/graph/badge.svg)](https://codecov.io/gh/VirtusLab/git-machete)
[//]: # (The image is referenced by its full URL to ensure it renders correctly on https://pypi.org/project/git-machete/)
💪 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.
[//]: # (The image is referenced by its full URL to ensure it renders correctly on https://pypi.org/project/git-machete/)
🔌 See also [VirtusLab/git-machete-intellij-plugin](https://github.com/VirtusLab/git-machete-intellij-plugin#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.
**Instructions for installing bash, zsh, and fish completion scripts are provided in [completion/README.md](completion/README.md).**
git-machete requires Python >= 3.6. Python 2.x is no longer supported.
### Using Homebrew (macOS & most Linux distributions)
```shell script
brew install git-machete
```
### Using snap (most Linux distributions)
**Tip:** check the [guide on installing snapd](https://snapcraft.io/docs/installing-snapd) if you don't have Snap support set up yet in your system.
```shell script
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.
```shell script
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](https://github.com/VirtusLab/git-machete/releases/latest)
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](https://repology.org/project/git-machete/versions) for the available distro-specific packages.
### Using Nix (macOS & most Linux distributions)
On macOS and most Linux distributions, you can install via [Nix](https://nixos.org/nix):
```shell script
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](https://repology.org/project/git-machete/versions) for the current channel-package mapping.
### Using pip with sudo (system-wide install)
You need to have Python and `pip` installed from system packages.
```shell script
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.
```shell script
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
```shell script
conda install -c conda-forge git-machete
```
## Quick start
### Discover the branch layout
```shell script
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
```shell script
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
```shell script
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
```shell script
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:
```shell script
git machete github checkout-prs [--all | --by= | --mine | ... ]
```
Create the PR, using the upstream (parent) branch from `.git/machete` as the base:
```shell script
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`](https://cli.github.com/) configuration.
4. Auth token from the current [`hub`](https://github.com/github/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?
[//]: # (For how to find Medium header anchors, see https://www.freecodecamp.org/news/how-to-link-to-a-specific-paragraph-in-your-medium-article-2018-table-of-contents-method-e66595fea549/)
No! It's all right, `discover` is based on an (imperfect)
[heuristic](https://medium.com/virtuslab/git-machete-strikes-again-traverse-the-git-rebase-jungle-even-faster-with-v2-0-f43ebaf8abb0#0544)
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`](https://git-machete.readthedocs.io/en/stable/#edit) to fix the layout manually.
If you're working on JetBrains IDEs, you can use [git-machete IntelliJ plugin](https://github.com/VirtusLab/git-machete-intellij-plugin#git-machete-intellij-plugin)
to have branch name completion when editing `.git/machete` file.
Also, consider [`git machete github checkout-prs`](#github-integration) 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`](https://git-machete.readthedocs.io/en/stable/#traverse)),
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-pick`s 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](https://slides.com/plipski/git-machete/#/11).
#### 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"](https://git-scm.com/book/en/v2/Git-Branching-Branches-in-a-Nutshell).
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_](https://medium.com/virtuslab/make-your-way-through-the-git-rebase-jungle-with-git-machete-e2ed4dbacd02#1ac9)
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](https://virtuslab.github.io/tips/#git/git-reflog)) 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...`](https://git-machete.readthedocs.io/#fork-point) command.
## Reference
Find the docs at [Read the Docs](https://git-machete.readthedocs.io/).
You can also check `git machete help` and `git machete help `.
For the excellent overview for the reasons to use small & stacked PRs,
see [Ben Congdon](https://github.com/bcongdon)'s [blog post](https://benjamincongdon.me/blog/2022/07/17/In-Praise-of-Stacked-PRs/).
Take a look at git-machete
[reference blog post](https://medium.com/virtuslab/make-your-way-through-the-git-rebase-jungle-with-git-machete-e2ed4dbacd02)
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](https://medium.com/virtuslab/git-machete-strikes-again-traverse-the-git-rebase-jungle-even-faster-with-v2-0-f43ebaf8abb0).
## Git compatibility
git-machete (since version 2.13.0) is compatible with git >= 1.8.0.
## Contributions
Contributions are welcome! See [contributing guidelines](CONTRIBUTING.md) 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.
%package help
Summary: Development documents and examples for git-machete
Provides: python3-git-machete-doc
%description help
# git-machete
[![homebrew formula](https://img.shields.io/homebrew/v/git-machete)](https://formulae.brew.sh/formula/git-machete)
[![PyPI package](https://img.shields.io/pypi/v/git-machete.svg)](https://pypi.org/project/git-machete)
[![PyPI package monthly downloads](https://img.shields.io/pypi/dm/git-machete.svg)](https://pypistats.org/packages/git-machete)
[![Conda package](https://img.shields.io/conda/vn/conda-forge/git-machete.svg)](https://anaconda.org/conda-forge/git-machete)
[![Conda downloads](https://img.shields.io/conda/dn/conda-forge/git-machete.svg)](https://anaconda.org/conda-forge/git-machete)
[![Snap](https://snapcraft.io/git-machete/badge.svg)](https://snapcraft.io/git-machete)
[![Read the Docs](https://readthedocs.org/projects/git-machete/badge/?version=latest)](https://git-machete.readthedocs.io/en/stable)
[![License: MIT](https://img.shields.io/github/license/VirtusLab/git-machete)](https://github.com/VirtusLab/git-machete/blob/master/LICENSE)
[![CircleCI](https://circleci.com/gh/VirtusLab/git-machete/tree/master.svg?style=shield)](https://app.circleci.com/pipelines/github/VirtusLab/git-machete?branch=master)
[![codecov](https://codecov.io/gh/VirtusLab/git-machete/branch/master/graph/badge.svg)](https://codecov.io/gh/VirtusLab/git-machete)
[//]: # (The image is referenced by its full URL to ensure it renders correctly on https://pypi.org/project/git-machete/)
💪 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.
[//]: # (The image is referenced by its full URL to ensure it renders correctly on https://pypi.org/project/git-machete/)
🔌 See also [VirtusLab/git-machete-intellij-plugin](https://github.com/VirtusLab/git-machete-intellij-plugin#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.
**Instructions for installing bash, zsh, and fish completion scripts are provided in [completion/README.md](completion/README.md).**
git-machete requires Python >= 3.6. Python 2.x is no longer supported.
### Using Homebrew (macOS & most Linux distributions)
```shell script
brew install git-machete
```
### Using snap (most Linux distributions)
**Tip:** check the [guide on installing snapd](https://snapcraft.io/docs/installing-snapd) if you don't have Snap support set up yet in your system.
```shell script
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.
```shell script
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](https://github.com/VirtusLab/git-machete/releases/latest)
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](https://repology.org/project/git-machete/versions) for the available distro-specific packages.
### Using Nix (macOS & most Linux distributions)
On macOS and most Linux distributions, you can install via [Nix](https://nixos.org/nix):
```shell script
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](https://repology.org/project/git-machete/versions) for the current channel-package mapping.
### Using pip with sudo (system-wide install)
You need to have Python and `pip` installed from system packages.
```shell script
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.
```shell script
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
```shell script
conda install -c conda-forge git-machete
```
## Quick start
### Discover the branch layout
```shell script
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
```shell script
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
```shell script
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
```shell script
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:
```shell script
git machete github checkout-prs [--all | --by= | --mine | ... ]
```
Create the PR, using the upstream (parent) branch from `.git/machete` as the base:
```shell script
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`](https://cli.github.com/) configuration.
4. Auth token from the current [`hub`](https://github.com/github/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?
[//]: # (For how to find Medium header anchors, see https://www.freecodecamp.org/news/how-to-link-to-a-specific-paragraph-in-your-medium-article-2018-table-of-contents-method-e66595fea549/)
No! It's all right, `discover` is based on an (imperfect)
[heuristic](https://medium.com/virtuslab/git-machete-strikes-again-traverse-the-git-rebase-jungle-even-faster-with-v2-0-f43ebaf8abb0#0544)
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`](https://git-machete.readthedocs.io/en/stable/#edit) to fix the layout manually.
If you're working on JetBrains IDEs, you can use [git-machete IntelliJ plugin](https://github.com/VirtusLab/git-machete-intellij-plugin#git-machete-intellij-plugin)
to have branch name completion when editing `.git/machete` file.
Also, consider [`git machete github checkout-prs`](#github-integration) 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`](https://git-machete.readthedocs.io/en/stable/#traverse)),
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-pick`s 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](https://slides.com/plipski/git-machete/#/11).
#### 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"](https://git-scm.com/book/en/v2/Git-Branching-Branches-in-a-Nutshell).
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_](https://medium.com/virtuslab/make-your-way-through-the-git-rebase-jungle-with-git-machete-e2ed4dbacd02#1ac9)
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](https://virtuslab.github.io/tips/#git/git-reflog)) 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...`](https://git-machete.readthedocs.io/#fork-point) command.
## Reference
Find the docs at [Read the Docs](https://git-machete.readthedocs.io/).
You can also check `git machete help` and `git machete help `.
For the excellent overview for the reasons to use small & stacked PRs,
see [Ben Congdon](https://github.com/bcongdon)'s [blog post](https://benjamincongdon.me/blog/2022/07/17/In-Praise-of-Stacked-PRs/).
Take a look at git-machete
[reference blog post](https://medium.com/virtuslab/make-your-way-through-the-git-rebase-jungle-with-git-machete-e2ed4dbacd02)
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](https://medium.com/virtuslab/git-machete-strikes-again-traverse-the-git-rebase-jungle-even-faster-with-v2-0-f43ebaf8abb0).
## Git compatibility
git-machete (since version 2.13.0) is compatible with git >= 1.8.0.
## Contributions
Contributions are welcome! See [contributing guidelines](CONTRIBUTING.md) 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.
%prep
%autosetup -n git-machete-3.17.4
%build
%py3_build
%install
%py3_install
install -d -m755 %{buildroot}/%{_pkgdocdir}
if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi
if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi
if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi
if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi
pushd %{buildroot}
if [ -d usr/lib ]; then
find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/lib64 ]; then
find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/bin ]; then
find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/sbin ]; then
find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst
fi
touch doclist.lst
if [ -d usr/share/man ]; then
find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst
fi
popd
mv %{buildroot}/filelist.lst .
mv %{buildroot}/doclist.lst .
%files -n python3-git-machete -f filelist.lst
%dir %{python3_sitelib}/*
%files help -f doclist.lst
%{_docdir}/*
%changelog
* Tue May 30 2023 Python_Bot - 3.17.4-1
- Package Spec generated