Skip to main content

Your First Repository in 5 Minutes

This quickstart guide will help you set up Git and make your first commit. Let’s get you up and running quickly!
1

Install Git

If you haven’t already installed Git, choose your platform:
brew install git
Verify installation:
git --version
2

Configure Your Identity

Tell Git who you are. This information will be attached to your commits:
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
Use the same email address you’ll use for GitHub, GitLab, or other Git hosting services.
3

Create Your First Repository

Initialize a new Git repository:
# Create a project directory
mkdir my-project
cd my-project

# Initialize Git
git init
You’ll see:
Initialized empty Git repository in /path/to/my-project/.git/
4

Make Your First Commit

Create a file and commit it:
# Create a README file
echo "# My Project" > README.md

# Stage the file
git add README.md

# Commit the changes
git commit -m "Initial commit"
The -m flag adds a commit message. Always write clear, descriptive commit messages!

Basic Daily Workflow

Once you have a repository, here’s the typical workflow:

1. Edit Files

Make changes to your files using your favorite editor.

2. Check Status

See what files have changed:
git status
Output:
On branch main
Changes not staged for commit:
  modified:   README.md

Untracked files:
  app.js

3. Stage Changes

Add files to the staging area:
# Stage specific files
git add README.md app.js

# Or stage all changes
git add .

4. Commit Changes

Save your staged changes:
git commit -m "Add initial application code"

Understanding Git Status

When you run git status, files can be in different states:

Untracked

New files that Git isn’t tracking yet

Modified

Tracked files that have been changed

Staged

Files ready to be committed

Viewing Changes

See what changed in files

# View unstaged changes
git diff

# View staged changes
git diff --staged

View commit history

# View commit log
git log

# View compact log
git log --oneline

# View log with graph
git log --graph --oneline --all

Quick Reference

Here are the most essential commands:
Initialize a new Git repository
git init
Stage files for commit
git add <file>        # Add specific file
git add .             # Add all changes
git add -p            # Interactive staging
Save staged changes
git commit -m "message"    # Commit with message
git commit -am "message"   # Stage and commit tracked files
git commit --amend         # Modify last commit
Check repository status
git status            # Full status
git status -s         # Short status
View commit history
git log               # Full log
git log --oneline     # Compact log
git log -n 5          # Last 5 commits
View changes
git diff              # Unstaged changes
git diff --staged     # Staged changes
git diff HEAD         # All changes

Practical Example

Let’s build a simple todo app:
# Create project
mkdir todo-app
cd todo-app
git init

# Create initial file
echo "# Todo App" > README.md
echo "[] Buy groceries" > todos.txt

# First commit
git add .
git commit -m "Initial commit with README and todos"

# Add more todos
echo "[] Walk the dog" >> todos.txt
echo "[] Study Git" >> todos.txt

# Check what changed
git diff

# Commit new todos
git add todos.txt
git commit -m "Add more todo items"

# View history
git log --oneline

Tips for Better Commits

Write Clear Commit MessagesGood:
  • Add user authentication feature
  • Fix navigation bug on mobile
  • Update README with installation steps
Avoid:
  • Update
  • Fix stuff
  • WIP
Commit FrequentlyMake small, focused commits rather than large ones. Each commit should represent one logical change.
Review Before CommittingAlways check git status and git diff before committing to make sure you’re committing what you intend.

Common Mistakes

Committing Without StagingIf you forget to run git add, your changes won’t be committed. Always stage files first!
Wrong Files in CommitBe careful not to commit sensitive files like passwords or API keys. Use .gitignore to prevent this.

Working with Existing Projects

To work on an existing Git project:
# Clone a repository
git clone https://github.com/username/repo.git

# Enter the directory
cd repo

# Make changes and commit
# (follow the workflow above)

Next Steps

Learn Core Concepts

Understand repositories, commits, and branches

Complete Tutorial

Follow our comprehensive step-by-step tutorial

Essential Commands

Deep dive into Git commands

Best Practices

Learn Git workflows and conventions

Cheat Sheet

CommandDescription
git initCreate new repository
git add <file>Stage file
git commit -m "msg"Commit changes
git statusCheck status
git logView history
git diffView changes
git clone <url>Clone repository
You’re now ready to start using Git! For more details, check out our Complete Tutorial or browse the Command Reference.