# Versioning tools

Version control is one of the most important best practices when programming in any
language. It allows you to track changes, collaborate with others, and maintain a history
of your work.

## Git

[Git] is the most widely used version control system today. It is a powerful tool,
although it can be somewhat challenging and potentially unsafe, especially for beginners.
**Git installation is optional for this training**, but recommended for your future work.

::::{tab-set}
:::{tab-item} Windows
Download and install from https://gitforwindows.org/.
:::

:::{tab-item} macOS
```sh
# this should already have been done, so Git should already be available
xcode-select --install
```

Alternately, you could install Git with:

```sh
brew install git
```
:::

:::{tab-item} Debian-Ubuntu-Mint
```sh
sudo apt install git
```
:::
::::

## Meld

[Meld] is a graphical diff and merge tool that integrates seamlessly with both Git and
Mercurial. It provides a visual interface for comparing files, reviewing changes, and
resolving merge conflicts, tasks that are much easier to understand visually than through
command-line output.

While **Meld installation is optional for this training**, it significantly improves your
version control workflow. Once you start using version control regularly, you'll find
Meld invaluable for understanding what changed in your code and handling complex merges.

::::{tab-set}
:::{tab-item} Windows
Download and run the installer from https://meldmerge.org/.
:::

:::{tab-item} macOS
```sh
brew install --cask meld
```
:::

:::{tab-item} Debian-Ubuntu-Mint
```sh
sudo apt install meld
```
:::
::::

## Mercurial

[Mercurial] is the version control system used for
[this training's repository](https://foss.heptapod.net/py-edu-fr/py-edu-fr), so **it is
highly recommended to install it to access the source code**.

Mercurial is similar to Git but offers some advantages: a simpler, more consistent
command interface, enhanced safety (no destructive operations), and excellent performance
for large repositories. While Git has become the standard for open-source projects
(GitHub, GitLab), Mercurial remains widely used in companies and offers powerful features
for collaborative development.

::::{tab-set}
:::{tab-item} Windows → WinGet
TortoiseHg (which includes Mercurial and useful extensions) can be installed using
[WinGet](https://learn.microsoft.com/en-us/windows/package-manager/winget/):

```powershell
winget install TortoiseHg.TortoiseHg -e --accept-package-agreements
```

Alternatively, you can
[download an installer](https://www.mercurial-scm.org/release/tortoisehg/windows/) and
run it to install TortoiseHG.
:::

:::{tab-item} Linux and macOS → UV
To install Mercurial with important extensions:

```sh
uv tool install "mercurial<7" --with hg-git,hg-evolve,certifi -p 3.13
```

**DO NOT USE this method on Windows!**
:::
::::

:::{admonition} Configure Mercurial
After installation, create a reasonable default configuration with:

```sh
uvx hg-setup init
```
:::

[git]: https://git-scm.com/
[meld]: https://meldmerge.org/
[mercurial]: https://www.mercurial-scm.org/
