Skip to content
Commencer

Installation et Configuration de Git

SlidesPDFPPTX
Niveau : Beginner
Durée : 1h15

Prérequis

  • Avoir un ordinateur sous Windows, macOS ou Linux
  • Savoir ouvrir un terminal (PowerShell, Terminal, Bash)
  • Disposer d'un compte GitHub (gratuit)

Objectifs d'apprentissage

  • Installer Git sur Windows, macOS et Linux et vérifier l'installation
  • Comprendre les trois niveaux de configuration (system, global, local)
  • Configurer votre identité Git globale (user.name, user.email, init.defaultBranch)
  • Configurer l'authentification moderne : SSH ed25519 et GitHub CLI (gh auth)
  • Personnaliser Git avec les aliases, l'éditeur et la gestion des credentials

Pourquoi bien configurer Git dès le départ ?

Section titled “Pourquoi bien configurer Git dès le départ ?”

Un Git mal configuré est la cause n°1 des erreurs débutant :

  • commits anonymes (Author: unknown <unknown@unknown>),
  • push qui demandent votre mot de passe à chaque fois,
  • branche par défaut master au lieu de main,
  • conflits d’éditeur (vim qui se bloque sans savoir comment quitter).

5 minutes de configuration aujourd’hui vous évitent des heures de debugging.

Sans config

Terminal window
git commit -m "test"
# Author: unknown <unknown>
git push
# Username for 'https://github.com':

Avec config

Terminal window
git commit -m "feat: add login"
# Author: Aïda Diallo <aida@hashcode.co>
git push
# → push instantané via SSH/gh

Choisissez votre système d’exploitation. Une seule section vous concerne :

Option A — Installateur officiel (recommandé)

Section titled “Option A — Installateur officiel (recommandé)”
  1. Téléchargez l’installateur :
  2. Lancez le .exe — gardez les options par défaut :
    • Editor : Visual Studio Code (si installé) ou Vim
    • Branch naming : Override to main
    • PATH : Git from the command line and also from 3rd-party software
    • Line endings : Checkout Windows-style, commit Unix-style
  3. Cochez Git Bash et Git GUI dans les composants
Terminal window
winget install --id Git.Git -e --source winget

Ouvrez PowerShell ou Git Bash :

Terminal window
git --version
# git version 2.45.1.windows.1
where git
# C:\Program Files\Git\cmd\git.exe
git --help

Commandes à exécuter

bash
# Cliquez sur les commandes à gauche pour les exécuter dans le simulateur
hashcode-academy:~$_

Git lit ses paramètres dans 3 fichiers en cascade (le plus précis gagne) :

<pre dir="ltr" class="mermaid">flowchart LR A[system&lt;br/&gt;/etc/gitconfig&lt;br/&gt;tous les users] --&gt; B[global&lt;br/&gt;~/.gitconfig&lt;br/&gt;vous seul] B --&gt; C[local&lt;br/&gt;.git/config&lt;br/&gt;un dépôt] C --&gt; D[Commande effective]</pre>
Niveau Fichier Commande Portée
system /etc/gitconfig git config --system Tous les utilisateurs de la machine
global ~/.gitconfig git config --global Vous sur tous vos dépôts
local .git/config git config --local Un seul dépôt
Terminal window
git config --list --show-origin
# file:/home/aida/.gitconfig user.name=Aïda Diallo
# file:/home/aida/.gitconfig user.email=aida@hashcode.co
# file:.git/config core.repositoryformatversion=0

Configuration identité & branche par défaut

Section titled “Configuration identité & branche par défaut”

C’est obligatoire avant votre premier commit. Sans cela chaque git commit échouera ou créera un auteur vide.

Commandes à exécuter

bash
# Cliquez sur les commandes à gauche pour les exécuter dans le simulateur
hashcode-academy:~$_

Correction d’une identité déjà committée

Section titled “Correction d’une identité déjà committée”
Terminal window
# Voir le dernier auteur
git log -1 --pretty=format:"%an <%ae>"
# Corriger uniquement le dernier commit
git commit --amend --reset-author --no-edit
# Corriger la config pour le futur
git config --global user.email "bonne.adresse@hashcode.co"

Authentification moderne : SSH & GitHub CLI

Section titled “Authentification moderne : SSH & GitHub CLI”

Le login/mot de passe GitHub n’existe plus depuis 2021. Deux méthodes modernes :

1. Clé SSH ed25519 (recommandé pour git push sans mot de passe)

Section titled “1. Clé SSH ed25519 (recommandé pour git push sans mot de passe)”

Commandes à exécuter

bash
# Cliquez sur les commandes à gauche pour les exécuter dans le simulateur
hashcode-academy:~$_
  1. Copiez le contenu de cat ~/.ssh/id_ed25519.pub 2. GitHub → Settings → SSH and GPG keys → New SSH key → Collez 3. Testez ssh -T git@github.com

Si vous voyez permission denied, vérifiez ssh-add ~/.ssh/id_ed25519 et eval "$(ssh-agent -s)".

2. GitHub CLI gh (utile pour PR/Issues depuis le terminal)

Section titled “2. GitHub CLI gh (utile pour PR/Issues depuis le terminal)”
Terminal window
# Installation
# Windows: winget install --id GitHub.cli
# macOS: brew install gh
# Linux: sudo apt install gh
gh auth login
# → GitHub.com → HTTPS → Yes → Paste an authentication token → …
gh auth status
# github.com
# ✓ Logged in to github.com account Aida (credential.helper=store)
gh repo clone joinhashcode/workshops
gh pr view --web

SSH

Idéal pour git clone git@github.com:..., push sans token, CI.

GH CLI

Idéal pour gh pr create, gh issue list, gh repo view, gh codespace.


Personnalisation avancée : aliases, couleurs, credential

Section titled “Personnalisation avancée : aliases, couleurs, credential”
Terminal window
git config --global alias.st status
git config --global alias.co checkout
git config --global alias.sw switch
git config --global alias.br branch
git config --global alias.lg "log --oneline --graph --all --decorate"
git config --global alias.last "log -1 --stat"

Testez :

Terminal window
git st
git lg
git last
Terminal window
git config --global color.ui auto
git config --global color.branch auto
git config --global color.diff auto

Credential helper — ne retaper jamais le token

Section titled “Credential helper — ne retaper jamais le token”
OS Commande
Windows git config --global credential.helper manager (GCM)
macOS git config --global credential.helper osxkeychain
Linux git config --global credential.helper store ou GCM

Vérifiez le helper actif :

Terminal window
git config --global --get credential.helper
[user]
name = Aïda Diallo
email = aida@hashcode.co
[init]
defaultBranch = main
[core]
editor = code --wait
[alias]
st = status
co = checkout
lg = log --oneline --graph --all --decorate
[color]
ui = auto
[credential]
helper = osxkeychain

Inspectez avec cat ~/.gitconfig ou git config --global --edit.



Question

Quelle commande vérifie que Git est correctement installé ?

Cliquer pour révéler la réponse
Réponse

git --version (et which git / where git pour le chemin)

Cliquer pour voir la question
Question

Quels sont les 3 niveaux de config Git et leur ordre de priorité ?

Cliquer pour révéler la réponse
Réponse

system (/etc/gitconfig) → global (~/.gitconfig) → local (.git/config). local gagne.

Cliquer pour voir la question
Question

À quoi sert --global dans git config ?

Cliquer pour révéler la réponse
Réponse

Applique le paramètre à tous les dépôts de l'utilisateur courant (~/.gitconfig). Sans, il faut spécifier --local ou --system.

Cliquer pour voir la question
Question

Quelles 2 infos sont obligatoires avant le premier commit ?

Cliquer pour révéler la réponse
Réponse

user.name et user.email (identité de l'auteur du commit).

Cliquer pour voir la question
Question

Quelle commande génère une clé SSH moderne ?

Cliquer pour révéler la réponse
Réponse

ssh-keygen -t ed25519 -C 'email@exemple.com'

Cliquer pour voir la question
Question

Quelle commande teste l'auth SSH GitHub ?

Cliquer pour révéler la réponse
Réponse

ssh -T git@github.com → 'Hi USER! You've successfully authenticated…'

Cliquer pour voir la question
Question

Quel alias affiche un log graph compact ?

Cliquer pour révéler la réponse
Réponse

git config --global alias.lg 'log --oneline --graph --all --decorate' → git lg

Cliquer pour voir la question
Question

Que faire si vous oubliez de fermer un guillemet ?

Cliquer pour révéler la réponse
Réponse

Le prompt affiche >. Tapez Ctrl + C pour annuler.

Cliquer pour voir la question

Quelle option configure votre identité pour TOUS vos dépôts ?

Quelle commande liste vos configs en montrant leur fichier d'origine ?

Quelle clé SSH est recommandée aujourd'hui ?

Comment tester que votre SSH GitHub fonctionne ?


Terminal window
# Installation
git --version
which git # Windows: where git
# Config — voir
git config --list
git config --list --show-origin
cat ~/.gitconfig
# Config — écrire
git config --global user.name "Prénom Nom"
git config --global user.email "email@exemple.com"
git config --global init.defaultBranch main
git config --global core.editor "code --wait"
git config --global color.ui auto
# Aliases
git config --global alias.st status
git config --global alias.lg "log --oneline --graph --all --decorate"
# SSH
ssh-keygen -t ed25519 -C "email@exemple.com"
cat ~/.ssh/id_ed25519.pub # → copier sur GitHub
ssh -T git@github.com
# GH CLI
gh auth login
gh auth status
gh repo clone joinhashcode/workshops

Votre Progression0%


Votre environnement est prêt et sécurisé. Créons maintenant votre tout premier dépôt local.

HashCode Workshops
Part of the JoinHashCode ecosystem

Ctrl + K Rechercher dans les workshops