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.
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.
To install Git on your system, follow these steps:
git --version. This should display the installed version of Git.Now that you have Git installed, let's create your first repository. A repository is a collection of files that are managed by Git.
mkdir my-first-repocd my-first-repogit inittouch readme.mdgit add readme.mdgit commit -m "First commit"git addAdds the changes made to a file or directory to the Git staging area, preparing them for commit.
git commitCreates a new commit with the changes in the staging area, along with a commit message describing the changes.
git statusShows the current status of the Git repository, including which files have been modified, which are staged, and which are untracked.
What does `git init` do?
Let's work on a practical example: a simple JavaScript project.
mkdir my-projectcd my-projectgit inittouch app.jsgit add app.jsgit commit -m "Initial commit"app.js:console.log("Hello, World!");console.log("Welcome to My Project!");git add app.jsgit 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! 🚀