Now that you've got Git installed and have initialized a new repository, it's time to make your first commit! Think of a commit as a snapshot of your project at a specific point in time. It's like saving your work with a descriptive note, so you can always go back to it or understand what changes were made and why.
The process involves a few key steps: adding files to be tracked, staging those changes, and then committing them. Let's break it down.
Step 1: Create or Modify a File First, let's create a new file in your project directory or make some changes to an existing one. For this example, let's create a simple README file to describe our project. Navigate to your project's root directory in your terminal and create a file named README.md. You can use your preferred text editor to add some content.
# My Awesome Project
This is a new project where I'm learning Git!Step 2: Check the Status
Before we commit, it's a good idea to see what Git knows about your project's files. The git status command will show you which files have been modified, which are untracked, and which are staged and ready to be committed.
git statusAfter creating your README.md file, running git status will likely show it as an 'untracked file'. This means Git sees the file exists but isn't actively tracking its changes yet.
Step 3: Stage Your Changes
To tell Git that you want to include this file in your next commit, you need to 'stage' it. This is done using the git add command. You can add specific files or all modified/untracked files.
git add README.mdNow, if you run git status again, you'll see that README.md is listed under 'Changes to be committed', usually in green. This indicates it's staged and ready for its snapshot.