Aller au contenu

Commandes Git

Copier toutes les commandes Générer PDF

Généralités Commandes Git et workflows pour le contrôle des versions sur toutes les plateformes.

Commandes de base

Command Description
git init Initialize a new Git repository
git clone <url> Clone a repository from remote URL
git status Show working directory status
git add <file> Add file to staging area
git add . Add all files to staging area
git commit -m "message" Commit staged changes with message
git push Push commits to remote repository
git pull Pull changes from remote repository

Branche

Command Description
git branch List all branches
git branch <name> Create new branch
git checkout <branch> Switch to branch
git checkout -b <name> Create and switch to new branch
git merge <branch> Merge branch into current branch
git branch -d <name> Delete branch

Opérations à distance

Command Description
git remote -v Show remote repositories
git remote add <name> <url> Add remote repository
git fetch Fetch changes from remote
git push origin <branch> Push branch to remote
git pull origin <branch> Pull branch from remote

Commandes avancées

Command Description
git log --oneline Show commit history in one line
git diff Show changes between commits
git reset --hard <commit> Reset to specific commit
git stash Temporarily save changes
git stash pop Apply stashed changes
git rebase <branch> Rebase current branch
git cherry-pick <commit> Apply specific commit
git tag <name> Create a tag

Flux de travail communs

Flux de travail de la branche des fonctions

# Create and switch to feature branch
git checkout -b feature/new-feature

# Make changes and commit
git add .
git commit -m "Add new feature"

# Push to remote
git push origin feature/new-feature

# Merge back to main
git checkout main
git merge feature/new-feature
git branch -d feature/new-feature

Flux de travail à chaud

```bash

Create hotfix branch from main

git checkout main git checkout -b hotfix/critical-bug

Fix the bug and commit

git add . git commit -m "Fix critical bug"

Merge to main and develop

git checkout main git merge hotfix/critical-bug git checkout develop git merge hotfix/critical-bug

Clean up

git branch -d hotfix/critical-bug ```_

Meilleures pratiques

Envoyer des messages

  • Utiliser le présent temps ("Ajout fonctionnalité" pas "Ajout fonctionnalité")
  • Garder la première ligne sous 50 caractères
  • Utilisez le corps pour expliquer quoi et pourquoi, pas comment
  • Questions de référence et demandes de retrait, le cas échéant

Stratégie de branchement

  • Utiliser des noms descriptifs de branches
  • Gardez les branches centrées sur des caractéristiques uniques
  • Supprimer les branches fusionnées
  • Synchroniser régulièrement avec la branche principale

Gestion des dépôts

  • Utilisez .gitignore pour exclure les fichiers inutiles
  • Gardez les commits atomiques et concentrés
  • Écrire des messages de commit significatifs
  • Utiliser des balises pour les versions
  • Sauvegardes régulières vers des dépôts distants