# Version Control with Git

> Track changes, branch safely, resolve conflicts and keep a clean history with Git. Free notes, key concepts, resources and a mini project.

Canonical: https://www.internhack.in/roadmaps/tracks/backend/git-version-control
Last updated: 2026-11-28

Track changes, branch safely, resolve conflicts and keep a clean history with Git.

Beginner · about 8 hours · difficulty 2/5

Learn first: [Linux and the Command Line](https://www.internhack.in/roadmaps/tracks/backend/linux-terminal)

Git records snapshots of your project so you can go back in time, work on features in isolation and collaborate without overwriting each other. Every professional backend team uses it.

### The mental model

A **commit** is a snapshot plus a pointer to its parent. A **branch** is just a movable label pointing at a commit. `HEAD` is where you are now. The **staging area** (index) lets you choose exactly what goes into the next commit. Once this clicks, commands stop feeling magical.

### Everyday workflow

- `git status`, `git add -p`, `git commit`, `git log --oneline --graph`
- `git switch -c feature/x` to branch, `git merge` or `git rebase` to integrate
- `git pull`, `git push`, and working with a remote called `origin`
- `git stash` to park unfinished work, `git restore` to discard changes

### Resolving conflicts

Conflicts happen when two branches change the same lines. Git marks the region; you edit the file to the correct final state, stage it and continue. Small, frequent commits and short-lived branches keep conflicts rare.

### Pitfalls

- Committing secrets such as `.env` files. Add them to `.gitignore` from day one; removing a secret from history is painful and the secret should be rotated anyway.
- Rewriting history (`rebase`, `push --force`) on branches others use.
- Giant commits with messages like "fix". Write messages that explain **why**.

You are ready to move on when you can branch, commit, rebase onto main, resolve a conflict and recover a "lost" commit with `git reflog`.

## Key concepts

- **Commits, staging and history**
- **Branching and merging**
- **Rebasing**
- **Resolving merge conflicts**
- **.gitignore**
- **Remotes: push, pull, fetch**
- **reflog and undoing mistakes**
- **Conventional commit messages**

## Mini project

Create a repo, make two branches that edit the same function differently, merge them to produce a conflict, resolve it, then practice an interactive rebase to squash commits.

## Check yourself

What is the difference between git merge and git rebase, and when would you avoid rebasing?

## Free resources

- [Pro Git (free book)](https://git-scm.com/book/en/v2) (git-scm.com)
- [Learn Git Branching](https://learngitbranching.js.org/) (learngitbranching.js.org)

Previous: [Linux and the Command Line](https://www.internhack.in/roadmaps/tracks/backend/linux-terminal) · Next: [Collaborating on Hosted Repositories](https://www.internhack.in/roadmaps/tracks/backend/repo-hosting)

## More in Your Daily Toolkit: Terminal and Git

- [Linux and the Command Line](https://www.internhack.in/roadmaps/tracks/backend/linux-terminal)
- [Version Control with Git](https://www.internhack.in/roadmaps/tracks/backend/git-version-control)
- [Collaborating on Hosted Repositories](https://www.internhack.in/roadmaps/tracks/backend/repo-hosting)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [Backend Developer Roadmap](https://www.internhack.in/roadmaps/tracks/backend)
