Skip to main content

Git - Cheat-Sheet

git-banner.jpg

Introduction

Git permet de faire du versioning notamment pour conserver et restaurer son code dans le temps.

Configuration d'un dépôt

Initialisation d'un dépôt

git init

Configurer les identifiants

  • Nom d'utilisateur :
git config --global user.name "<Username>"
  • Email :
git config --global user.email "<MAIL@EMAIL.COM>"

Configurer un dépôt distant

git remote add origin <REPOS_URL>

 

git fetch

Gestion d'un dépôt

Ajouter les fichiers modifiés

git add .

Faire un commit

git commit -m "<COMMIT_MESSAGE>"

Faire un push

git push origin <BRANCH>

Remarque : La branche principale se nomme main .

Récupérer les fichiers d'un dépôt distant sans fusion

git fetch

Récupérer les fichiers du dépôt distant

git pull origin <BRANCH>

Remarque : La commande git pull est une combinaison de git fetch et git merge.

Gestion des branches

Créer une branche

git branch <BRANCH_NAME>

Basculer sur une branche

git checkout <BRANCH_NAME>

Lister les branches

git branch

Fusionner une branche avec la branche actuelle

git merge <BRANCH_NAME>

Autre

Cloner un dépôt

git clone <REPOS_URL>