Beginner15 minutesGitLevel 1

Basic Git Commands

Learning Objectives

By the end of this lesson, you'll be able to:

  • Initialize a Git repository
  • Stage and commit changes
  • Check the status of your repository
  • View commit history

Why This Matters:

These basic commands are the ones you will use every single day as a developer. Mastering them now builds the muscle memory you need for efficient version control.

Before You Start:

You should be familiar with:

  • Have Git installed and configured
  • Have a project folder ready to use for practice

Step 1: Initialize a Repository

To start tracking a project with Git, use the git init command. This sets up a new Git repository in your project folder by creating a hidden .git folder, which Git uses to track changes.

Open your terminal, navigate to your project folder, and run:

Step 2: Check Repository Status

Use the git status command to see the current state of your repository. It shows which files are staged, unstaged, or untracked (new files not yet added to Git).

To check the status of your repository, run:

Step 3: Stage Changes

To prepare changes for a commit, you need to stage them. Use git add <file-name> to stage a specific file, or git add . to stage all changes in the repository. Staging means preparing the files to be included in the next snapshot of your project.

To stage a specific file, use:

To stage all changes in the repository, use:

Step 4: Commit Changes

Once your changes are staged, use the git commit -m 'Your commit message' command to save them to the repository. The commit message should briefly describe the changes you made.

To commit your staged changes, run:

The commit message should briefly describe the changes you made.

Step 5: View Commit History

Use the git log command to view the history of commits in your repository. Each commit includes details like the author, date, a unique hash identifier, and the commit message.

To see a list of all commits in your repository, use:

Try It Yourself

Use the interactive terminal below to practice the basic Git commands:

Setting Up Git in VS Code

Visual Studio Code has built-in Git support, making it easy to manage your repositories directly from the editor. Follow these steps to set up Git in VS Code:

Step 1: Open the Source Control Panel

Click on the Source Control icon in the Activity Bar on the left side of the editor. If you have a Git repository initialized in your project folder, it will automatically appear here.

Step 2: Configure Git in VS Code

If you haven't already configured Git globally, VS Code will prompt you to set your name and email. You can also configure it manually by running the following commands in the integrated terminal:

Step 3: Commit Changes

To commit changes, stage your files by clicking the icon next to the file name in the Source Control panel. Then, enter a commit message in the text box and click the checkmark icon to commit.

Step 4: Push and Pull Changes

Use the Source Control panel to push your changes to a remote repository or pull changes from it. You can also use the integrated terminal to run git push and git pull commands.

Step 5: View Git History

Install the Git History extension to view your commit history in a visual format. This can be helpful for tracking changes and understanding your project's timeline.

🏁 Lesson Complete: Basic Git Commands

Key Takeaways:

  • git init creates a new repository in your project folder
  • git status shows you which files are modified, staged, or untracked
  • git add stages files to prepare them for committing
  • git commit saves a snapshot of your staged changes with a descriptive message
  • git log shows your commit history so you can review past changes

Learning Objectives Review:

Look back at what you set out to learn. Can you now:

  • ✅ Initialize a Git repository Check!
  • ✅ Stage and commit changes Got it!
  • ✅ Check the status of your repository Can explain it!
  • ✅ View commit history Could teach this!

If you can confidently answer "yes" to most of these, you're ready to move on!

Think & Reflect:

💭 💭 Reflection Questions

  • What is the difference between staging and committing?
  • Why is it important to write clear commit messages?
  • How often should you commit your changes?

🎯 Looking Ahead:

Now that you know the basic commands, you're ready to learn about branching—one of Git's most powerful features for working on multiple things at once.

Recommended Next Steps

Continue Learning

Ready to move forward? Continue with the next tutorial in this series:

Branching

Related Topics

Explore these related tutorials to expand your knowledge:

Practice Projects

Apply what you've learned with these hands-on projects:

Commit Practice

Make multiple commits and view the log.

gitcommitlog
Start Project

Additional Resources

Deepen your understanding with these helpful resources:

Progress tracking is disabled. Enable it in to track your completed tutorials.