Study Shelf / Git

Git Commands Guide

A practical note with essential Git commands, quick explanations, and examples I can reuse while studying or helping someone else.

Mini History of Git

In April 2005, Linus Torvalds created Git to manage the Linux kernel. Before Git, centralized systems like CVS and Subversion were slower and more rigid. Git introduced performance, lightweight branches, and a distributed workflow that changed collaborative development.

Essential Commands

1. Start a repository

# In a new or existing directory
git init

This creates the .git folder and starts version control.

2. Clone a remote project

git clone https://github.com/user/project.git

Downloads the full project to your machine.

3. Add files to staging

# Add a specific file
git add file.txt

# Add all changes
git add .

Use before running git commit.

4. Create a commit

git commit -m "Implement login feature"

Registers the staged changes in the repository history.

5. Check current status

git status

Shows modified, untracked, and staged files.

6. View commit history

git log --oneline

Displays a compact list of commits.

7. Work with branches

# Create a branch
git branch my-feature

# Switch to the branch
git switch my-feature

Branches help isolate work before merging it back.