← Back to Chapters

Git Get Started

? Git Get Started

? Quick Overview

Now that you've installed Git and configured it, it's time to start using it. This topic covers creating repositories, tracking changes, making commits, and understanding basic Git workflows.

? Key Concepts

  • Repository initialization
  • Staging and committing changes
  • Remote repositories
  • Branching workflow

? Creating a Git Repository

Navigate to your project folder and run:

? View Code Example
// Initialize a new Git repository
git init

? Cloning an Existing Repository

? View Code Example
// Clone a remote repository to local system
git clone <repository-url>

? Checking Repository Status

? View Code Example
// Show modified, staged, and untracked files
git status

➕ Adding Changes to Staging Area

? View Code Example
// Add a specific file to staging area
git add file.txt
? View Code Example
// Add all project files to staging area
git add .

✅ Committing Changes

? View Code Example
// Commit staged changes with message
git commit -m "Initial commit"

? Viewing Commit History

? View Code Example
// View commit logs
git log

? Pushing Changes to Remote

? View Code Example
// Push local commits to remote branch
git push origin main

? Pulling Remote Changes

? View Code Example
// Fetch and merge changes from remote
git pull origin main

? Branching Basics

? View Code Example
// Create a new branch
git branch feature-login
? View Code Example
// Switch to another branch
git checkout feature-login
? View Code Example
// Create and switch branch in one command
git checkout -b feature-ui

? Git Workflow (Visual Explanation)

Working Directory → Staging Area → Repository → Remote

This flow helps track, review, and safely share your code changes.

? Use Cases

  • Version control for solo and team projects
  • Safe experimentation using branches
  • Collaboration using GitHub or GitLab

? Tips & Best Practices

  • Commit small logical changes frequently
  • Always pull before starting new work
  • Use branches for features and fixes
  • Write meaningful commit messages

? Try It Yourself

  • Create a new Git repository
  • Add and commit a file
  • Create a new branch and switch to it
  • Push your project to GitHub