# Git Basics — Install, init, add, commit, status, log and diff

Source: https://skills101.in/learn/git/git-basics — Skills101 free tutorial (Git & GitHub). Updated 2026-11-09.

**Git** keeps the full history of your code. You can see what changed, when and why, go back to any earlier version, and work with a team without overwriting each other's work. Every software company uses it — and recruiters look at your **GitHub** profile.

## 1. Install and configure (once)

Download from git-scm.com (Windows) or `sudo apt install git` (Linux). Then tell Git who you are:

```bash
git config --global user.name "Asha Verma"
git config --global user.email "asha@example.com"
git config --global init.defaultBranch main
```

## 2. The three areas

![Files move from the working directory to the staging area with git add, and from staging to the repository with git commit; git restore brings files back](https://skills101.in/learn-img/git/three-areas.svg)

| Area | What it is |
|---|---|
| **Working directory** | the files you're editing |
| **Staging area** (index) | the changes you've **chosen** for the next commit |
| **Repository** (`.git` folder) | the saved history of commits |

Staging lets you commit **related** changes together, even if you edited many files.

## 3. Everyday commands

```bash
mkdir portfolio && cd portfolio
git init                       # start tracking this folder
echo "# My Portfolio" > README.md
git status                     # what changed? what is staged?
git add README.md              # stage one file (git add . = everything)
git commit -m "Add README"     # save a snapshot with a message
git log --oneline              # history, one line per commit
```

```text
a1b2c3d (HEAD -> main) Add README
```

(Commit ids — "hashes" — will be different on your computer.)

### See exactly what changed

```bash
git diff              # unstaged changes
git diff --staged     # staged changes (what will be committed)
git show a1b2c3d      # one commit's changes
```

## 4. Commits are a chain of snapshots

![Four commits — init, add login, fix bug, add tests — each pointing to its parent; main and HEAD point to the latest](https://skills101.in/learn-img/git/commit-chain.svg)

Each commit has a unique id, an author, a time, a message and a pointer to its **parent**. **HEAD** marks the commit you're on.

## 5. Good commit messages

- Short summary in the **imperative**: "Add login form", "Fix price rounding" (not "added stuff").
- One logical change per commit.
- Commit often — small commits are easy to understand and undo.

## 6. .gitignore: files Git should never track

Create a `.gitignore` file:

```text
node_modules/
.env
*.log
dist/
__pycache__/
```

> **Never commit secrets** (passwords, API keys, `.env` files). Once pushed to GitHub, assume they're leaked — rotate them immediately.

## Common mistakes

- Running `git init` in your home folder (it tracks everything!).
- Huge commits with messages like "update".
- Committing `node_modules` or `.env`.

## Quick recap

- Configure name and email once.
- Working directory → `git add` → staging → `git commit` → repository.
- `status`, `diff`, `log --oneline`, `show` to look around.
- Small commits, clear messages, `.gitignore` for build files and secrets.


Practice quiz and free certificate: https://skills101.in/learn/git/git-basics