# Git Fundamentals

> Track changes, work on branches, merge and recover from mistakes with Git, the backbone of every pipeline and GitOps workflow. Free notes, key concepts,...

Canonical: https://www.internhack.in/roadmaps/tracks/devops/git-fundamentals
Last updated: 2026-11-28

Track changes, work on branches, merge and recover from mistakes with Git, the backbone of every pipeline and GitOps workflow.

Beginner · about 8 hours · difficulty 2/5

Learn first: [Linux Command Line and Packages](https://www.internhack.in/roadmaps/tracks/devops/linux-basics)

In DevOps, Git is more than source control. Pipelines trigger on pushes, infrastructure is reviewed as pull requests, and GitOps tools treat a repository as the source of truth for what runs in production.

### Core model

- A repository is a graph of **commits**; each commit is a snapshot with a parent. **Branches** and **tags** are pointers to commits. `HEAD` is where you are.
- The three areas: working tree, **staging area** (index), and history.
- Everyday commands: `status`, `add -p`, `commit`, `log --oneline --graph`, `diff`, `switch`, `merge`, `rebase`, `pull`, `push`, `fetch`.

### Recovering

`git restore`, `git reset` (soft, mixed, hard), `git revert` for undoing a pushed commit safely, `git reflog` to find "lost" work, and `git stash`.

### Hygiene

- Write meaningful commit messages; conventional commits help automate changelogs.
- Use `.gitignore` and never commit secrets. If you do, rotate the secret: rewriting history is not enough.
- Tag releases (`v1.4.0`) so pipelines and rollbacks have stable references.
- Signed commits and pre-commit hooks for linting.

**Good enough to move on:** you can branch, rebase onto main, resolve a conflict, revert a bad commit on a shared branch, and recover a dropped commit with reflog.

## Key concepts

- **Commits, branches and HEAD**
- **Staging and partial commits**
- **Merge vs rebase**
- **Resolving conflicts**
- **revert, reset and reflog**
- **Tags and releases**
- **.gitignore and secret hygiene**
- **pre-commit hooks**

## Mini project

Create a repo for your dotfiles or scripts, practise a feature branch with a deliberate merge conflict, revert a commit, and add a pre-commit hook that runs ShellCheck.

## Check yourself

A teammate pushed a commit with a bug to main. Why should you use git revert instead of git reset there?

## Free resources

- [Pro Git](https://git-scm.com/book/en/v2) (git-scm.com)
- [GitHub Docs: Get started](https://docs.github.com/en/get-started) (GitHub)

Previous: [SSH, Bastions and VPNs](https://www.internhack.in/roadmaps/tracks/devops/ssh-vpn) · Next: [Branching Strategies and Pull Requests](https://www.internhack.in/roadmaps/tracks/devops/branching-workflows)

## More in Git and Collaboration Workflows

- [Git Fundamentals](https://www.internhack.in/roadmaps/tracks/devops/git-fundamentals)
- [Branching Strategies and Pull Requests](https://www.internhack.in/roadmaps/tracks/devops/branching-workflows)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [DevOps Engineer Roadmap](https://www.internhack.in/roadmaps/tracks/devops)
