Pour forker un projet Git et le rebaser sur votre propre dépôt, suivez ces étapes :

1. Forker le Projet

  • Créez un fork du projet sur GitHub en utilisant l’interface web ou la commande gh repo fork.
  • Clonez votre fork localement avec git clone https://github.com/VOTRE-NOMUTILISATEUR/NOM-DU-PROJET.git.

2. Configurer le Dépôt Upstream

  • Ajoutez le dépôt original comme remote upstream : bash git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git
  • Vérifiez les remotes avec git remote -v.

3. Synchroniser avec Upstream

  • Récupérez les dernières modifications du dépôt original : bash git fetch upstream
  • Mettez à jour votre branche principale avec les modifications d’upstream : bash git checkout main git merge upstream/main

4. Créer une Branche de Fonctionnalité

  • Créez une nouvelle branche pour vos modifications : bash git checkout -b votre-branche

5. Rebaser Votre Branche

  • Rebasez votre branche sur la branche principale mise à jour : bash git rebase main
  • Résolvez les conflits si nécessaire, puis continuez le rebase avec : bash git add . git rebase --continue

6. Pousser les Modifications

  • Poussez votre branche vers votre fork : bash git push origin votre-branche

7. Créer une Pull Request

  • Créez une Pull Request depuis votre fork vers le dépôt original pour soumettre vos modifications.

Bonnes Pratiques

  • Évitez de rebaser les branches partagées.
  • Sauvegardez vos modifications avant de commencer un rebase.
  • Utilisez git reflog pour récupérer des commits perdus en cas de problème.

Pour aller plus loin :

Gitlab : https://docs.gitlab.com/ee/user/project/repository/forking_workflow.html.

Github : https://docs.github.com/fr/pull-requests/collaborating-with-pull-requests/working-with-forks/fork-a-repo

Git : https://git-scm.com/docs/git-rebase