Initializing a Repository and Making Your First Commit

Difficulty: beginner
Est. Time: 30 minutes
Prerequisites:
  • Git Installation and Configuration
Initializing a Repository and Making Your First Commit
10 min
TUTORIAL
git
repository
commit
beginner

Initializing a Repository and Making Your First Commit

Now that you’ve installed Git, let’s dive into creating your first repository and making your first commit. This blog will walk you through initializing a Git repository, staging files, and committing changes.

Table of Contents

  • Repository (Repo)
  • Staging Area
  • Commit
  • Steps to Initialize a Repo
  • Exercise: Creating and Committing

Repository (Repo)

A repository is a directory where Git tracks changes. It contains all the files and their revision history.

Staging Area

The staging area is where you prepare changes before committing them.

Commit

A commit is a saved snapshot of your project at a specific point in time.

Steps to Initialize a Repo

  1. Create a new directory and navigate into it:
  2. 
      mkdir my-first-repo
      cd my-first-repo
                
  3. Initialize the repository:
  4. 
      git init
                
  5. Create a file and add content:
  6. 
      echo "Hello, Git!" > README.md
                
  7. Stage the file:
  8. 
      git add README.md
                
  9. Commit the file:
  10. 
      git commit -m "Initial commit"
                

Git Graph After Commit

Commit A (Initial commit)

Exercise

Create a new directory and initialize it as a Git repository. Add a file called hello.txt with some content. Stage and commit the file with a meaningful message. Run git log to view your commit history.

Coming Up Next

In the next part of this series, we’ll explore branching and merging in Git, allowing you to work on different versions of your project simultaneously.

Part 2 of 24 in Git Mastery Series: From Beginner to Expert
All Posts in This Series