Git Introduction 🎯

beginner
14 min

Git Introduction 🎯

Welcome to the Git Introduction lesson! In this tutorial, you'll learn how to use Git, a powerful tool for version control and collaboration. By the end of this lesson, you'll be able to manage your code with ease, track changes, and work on projects with others.

What is Git? 📝

Git is a distributed version control system designed to help you manage changes to your code, collaborate with others, and maintain the integrity of your projects. It allows you to keep a history of your code, compare changes, and revert back to previous versions if needed.

Why Use Git? 💡

  • Track Changes: Git helps you keep track of every change made to your code, making it easy to see who made changes and what they were.
  • Collaboration: Git makes it easy to work on the same project with others, allowing multiple developers to contribute and merge their changes seamlessly.
  • Backup and Recovery: Git keeps a history of your code, making it easy to recover old versions or revert back to a specific point in time.

Installing Git ✅

To install Git on your system, follow these steps:

  1. Go to the official Git download page and download the version appropriate for your operating system.
  2. Follow the installation instructions for your operating system.
  3. Verify the installation by opening a terminal or command prompt and running the command git --version. This should display the installed version of Git.

Your First Git Repository 💡

Now that you have Git installed, let's create your first repository. A repository is a collection of files that are managed by Git.

  1. Create a new directory for your project: mkdir my-first-repo
  2. Navigate to the new directory: cd my-first-repo
  3. Initialize the directory as a Git repository: git init
  4. Create a new file: touch readme.md
  5. Add the new file to the Git repository: git add readme.md
  6. Commit the changes: git commit -m "First commit"

Git Commands 📝

git add

Adds the changes made to a file or directory to the Git staging area, preparing them for commit.

git commit

Creates a new commit with the changes in the staging area, along with a commit message describing the changes.

git status

Shows the current status of the Git repository, including which files have been modified, which are staged, and which are untracked.

Quiz 🎯

Quick Quiz
Question 1 of 1

What does `git init` do?

Practical Example 💡

Let's work on a practical example: a simple JavaScript project.

  1. Create a new directory: mkdir my-project
  2. Navigate to the new directory: cd my-project
  3. Initialize the directory as a Git repository: git init
  4. Create a new JavaScript file: touch app.js
  5. Add the new file to the Git repository: git add app.js
  6. Commit the changes: git commit -m "Initial commit"
  7. Add the following code to app.js:
javascript
console.log("Hello, World!");
  1. Make a change to the code:
javascript
console.log("Welcome to My Project!");
  1. Add the changed file to the Git staging area: git add app.js
  2. Commit the changes: git commit -m "Updated the message"

Congratulations! You've completed your first Git project. You now have a versioned JavaScript project, and you can track your changes as you work on it.

Keep learning, and happy coding! 🚀