Skip to main content

01. Git Fundamentals and Setup

Level: Beginner

ℹ️ What You'll Learn
  • Why version control matters for teams
  • Install and configure Git
  • Create your first repository
  • Track changes with add/commit
  • Check status and history
  • Set up SMS project in Git

The Problem

Working alone on code is fine. Working on a team without version control is chaos. Who made which change? Can we revert the broken code? Did someone's work conflict with mine? Git solves this. Every professional .NET project uses Git.

Install Git

Download from: https://git-scm.com/download

Windows: Git for Windows installer

Post-install, verify:

git --version
# git version 2.43.0

Configure User

First time setup:

git config --global user.name "TeamSahasra"
git config --global user.email "team@sahasratechnologies.com"
git config --global core.editor "code" # Use VS Code as default editor

Verify:

git config --list

Initialize Repository

Navigate to project:

cd C:\NexCoding\SMS
git init

Creates .git folder (hidden).

Basic Workflow

1. Make changes to files

# Edit StudentService.cs
# Edit Program.cs

2. Check status

git status
# Modified: StudentService.cs
# Modified: Program.cs
# Untracked: Tests.cs

3. Stage changes

git add StudentService.cs Program.cs
# or add all:
git add .

4. Commit

git commit -m "Add student CRUD operations"

5. View history

git log

Common Commands

CommandPurpose
git initCreate repository
git addStage files
git commitSave snapshot
git logView history
git statusSee changes
git diffCompare versions

SMS Example

# Navigate to SMS project
cd C:\NexCoding\SMS

# Initialize
git init

# Create Student model
# Create StudentService
# Create Unit tests

# Check status
git status
# Modified: StudentService.cs (new)
# Untracked: Tests/StudentServiceTests.cs

# Stage changes
git add .

# Commit
git commit -m "Add StudentService with CRUD methods"

# View commit
git log -1
# commit abc123...
# Author: TeamSahasra
# Date: Today
# Add StudentService with CRUD methods

.gitignore

Create .gitignore file:

# Visual Studio
bin/
obj/
.vs/
*.csproj.user

# Packages
packages/
.nuget/

# Logs
*.log
logs/

# Secrets
appsettings.local.json
secrets.json

Prevents committing build artifacts, secrets, logs.

Key Takeaways

  • Git = version control (track changes)
  • Repository = folder with .git/
  • Commit = snapshot at a point in time
  • History = see who changed what and when
  • .gitignore = exclude files
💡 Commit Pro Tip

Commit frequently with clear messages. Makes history readable.

🤖Use AI to Learn Faster

Use ChatGPT, Claude, or Copilot to go deeper on Git Setup. Try these prompts:

  • "How do I initialize a Git repository?"
  • "What should be in .gitignore?"
  • "How do I commit changes?"
  • "Quiz me on Git basics"

💡 Tip: After reading this article, paste your own code into AI and ask "What could go wrong here and why?" — fastest way to find edge cases and deepen understanding.

nexcoding.in