Maîtriser les interactions avec GitHub : clone, push, pull, fetch, gestion des branches distantes, et workflow collaboratif simple.
Avoir un compte GitHub et une clé SSH configurée (voir fiche GitHub 1). Connaître les bases de Git (fiches Git 1 et 2).
Une fois un dépôt créé sur GitHub, il faut le lier à votre dépôt local :
| Commande | Exemple | Description |
|---|---|---|
| git remote add origin <url> | git remote add origin git@github.com:user/mon-projet.git | Associe le dépôt distant nommé 'origin' à votre dépôt local. |
| git push -u origin main | git push -u origin main | Envoie les commits vers GitHub ET établit le suivi (upstream). |
| git remote -v | git remote -v | Affiche les dépôts distants configurés. |
| git remote set-url origin <new-url> | git remote set-url origin git@github.com:user/nouveau.git | Change l'URL du dépôt distant. |
| git remote rm <nom> | git remote rm origin | Supprime un dépôt distant. |
# Créer un dépôt sur GitHub (via l'interface web) # Puis en local : mkdir mon-projet cd mon-projet git init echo "# Mon Projet" > README.md git add README.md git commit -m "Premier commit" # Lier au dépôt GitHub git remote add origin git@github.com:user/mon-projet.git git push -u origin main
| Commande | Exemple | Description |
|---|---|---|
| git clone <url> | git clone git@github.com:user/mon-projet.git | Copie le dépôt distant dans un dossier local. |
| git clone <url> <nom> | git clone git@github.com:user/mon-projet.git mon-dossier | Clone dans un dossier spécifique. |
| git clone --depth 1 <url> | git clone --depth 1 git@github.com:user/gros-projet.git | Clone superficiel (seul le dernier commit). |
| git clone --branch <branche> <url> | git clone --branch develop git@github.com:user/projet.git | Clone une branche spécifique. |
# Cloner un projet git clone git@github.com:user/mon-projet.git cd mon-projet # Lister les branches locales et distantes git branch -a # Voir le dépôt distant configuré git remote -v
| Commande | Exemple | Description |
|---|---|---|
| git push | git push origin main | Envoie les commits de la branche courante vers le dépôt distant. |
| git pull | git pull origin main | Récupère ET fusionne les modifications distantes dans la branche courante. |
| git fetch | git fetch origin | Récupère les modifications sans les fusionner (vérifier avant). |
| git pull --rebase | git pull --rebase origin main | Récupère et rebase (historique linéaire). |
| git push --tags | git push --tags | Envoie les tags (versions) vers le dépôt distant. |
| Commande | Exemple | Description |
|---|---|---|
| git push origin <branche> | git push origin feature-login | Pousse une branche locale vers le dépôt distant. |
| git push -u origin <branche> | git push -u origin feature-login | Push + établit le suivi. |
| git checkout <branche> | git checkout feature-login | Bascule sur une branche locale existante. |
| git checkout -b <branche> origin/<branche> | git checkout -b develop origin/develop | Crée une branche locale à partir d'une branche distante. |
| git branch --track <branche> origin/<branche> | git branch --track feature origin/feature | Crée une branche locale avec suivi d'une branche distante. |
| git push origin --delete <branche> | git push origin --delete feature-login | Supprime une branche distante. |
| git branch -d <branche> | git branch -d feature-login | Supprime la branche locale (si fusionnée). |
# Créer une nouvelle branche et la pousser git checkout -b feature-login git add . git commit -m "Ajout login" git push -u origin feature-login # Supprimer la branche distante après fusion git push origin --delete feature-login git branch -d feature-login
1. Cloner le dépôt git clone git@github.com:user/projet.git cd projet 2. Créer une branche pour une fonctionnalité git checkout -b feature-ajout-contact 3. Travailler et committer git add . git commit -m "Ajout du formulaire de contact" 4. Pousser la branche sur GitHub git push -u origin feature-ajout-contact 5. Ouvrir une Pull Request sur GitHub (interface web) 6. Après validation et merge, revenir sur main git checkout main git pull origin main 7. Supprimer la branche locale git branch -d feature-ajout-contact
✅ Réponse : git remote add origin <url>
✅ Réponse : Il pousse les commits ET établit le suivi de la branche distante
✅ Réponse : git fetch
✅ Réponse : git push origin --delete <branche>
✅ Réponse : origin