Tutoriel Git et Github pour les débutants : Les bases fondamentales

3 min read 2 hours ago
Published on Oct 19, 2024 This response is partially generated with the help of AI. It may contain inaccuracies.

Table of Contents

Introduction

This tutorial aims to introduce beginners to Git, a version control system, and GitHub, a popular web service for hosting Git repositories. By following these steps, you will gain a foundational understanding of how to manage and collaborate on projects using these tools.

Step 1: Understanding Version Control

  • Version control is a system that records changes to files over time, allowing you to revert to specific versions when necessary.
  • Git is a distributed version control system, meaning every user has a full copy of the repository.
  • Key benefits of using Git include:
    • Collaboration with others on projects.
    • Keeping track of project history.
    • Experimenting with features without affecting the main codebase.

Step 2: Installing Git

  • Download Git from the official website: Git Downloads.
  • Follow the installation instructions for your operating system (Windows, macOS, or Linux).
  • After installation, verify it by opening your terminal or command prompt and typing:
    git --version
    

Step 3: Configuring Git

  • Set up your username and email address, which will be associated with your commits:
    git config --global user.name "Your Name"
    git config --global user.email "your.email@example.com"
    
  • Check your configurations with:
    git config --list
    

Step 4: Creating a New Repository

  • Navigate to your project directory in the terminal.
  • Initialize a new Git repository by running:
    git init
    
  • This command creates a new .git directory, which tracks all changes.

Step 5: Adding Files to the Repository

  • To start tracking files, add them to your staging area using:
    git add filename
    
  • To add all files in the directory, use:
    git add .
    

Step 6: Committing Changes

  • Commit your changes to the repository with a descriptive message:
    git commit -m "Your commit message"
    

Step 7: Understanding Branching

  • Create a new branch to work on a feature without affecting the main branch:
    git branch new-feature
    
  • Switch to that branch:
    git checkout new-feature
    
  • Merge changes back into the main branch once finished:
    git checkout main
    git merge new-feature
    

Step 8: Working with GitHub

  • Create an account on GitHub if you don’t have one.
  • Create a new repository on GitHub.
  • Link your local repository to GitHub:
    git remote add origin https://github.com/username/repo.git
    
  • Push your changes to GitHub:
    git push -u origin main
    

Step 9: Collaborating with Others

  • To collaborate, others can clone your repository using:
    git clone https://github.com/username/repo.git
    
  • They can create branches, make changes, and submit pull requests for review.

Conclusion

By following these steps, you have learned the basics of Git and GitHub, from installation and configuration to creating repositories and collaborating with others. You can now manage your projects effectively and take advantage of version control. As you continue to explore, consider experimenting with more advanced features, such as rebasing and conflict resolution, to further enhance your skills.