# Professional Git Workflow and Git Interview Questions

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

You know the commands. This lesson shows how they fit together in a real team — and how to answer Git questions in interviews.

![The pull request workflow: branch, small commits, push, open a PR, review and checks, merge](https://skills101.in/learn-img/git/pr-workflow.svg)

## 1. A day at work with Git

```bash
git switch main && git pull                 # start from the latest main
git switch -c fix/upi-timeout               # one branch per task
# ... code, test ...
git add -p                                  # review and stage hunk by hunk
git commit -m "Retry UPI status check on timeout"
git pull --rebase origin main               # update your branch with main (your own branch only)
git push -u origin fix/upi-timeout
# open a PR, address review comments, push more commits, merge
```

### Team rules you'll see

- **main is protected** — no direct pushes; changes arrive through PRs.
- **CI** (GitHub Actions) runs tests on every PR.
- **Code review** — at least one approval.
- **Squash merge** — a PR becomes one clean commit on main.
- **Tags** mark releases: `git tag v1.4.0 && git push --tags`.

## 2. Cheat sheet

| Task | Command |
|---|---|
| Start / copy a repo | `git init` · `git clone URL` |
| See state | `git status` · `git log --oneline --graph` · `git diff` |
| Save work | `git add .` · `git commit -m "msg"` |
| Branches | `git switch -c name` · `git switch name` · `git branch -d name` |
| Combine | `git merge name` · `git rebase main` |
| Sync | `git pull` · `git push` · `git fetch` |
| Undo | `git restore` · `git reset` · `git revert` · `git stash` |
| Investigate | `git blame file` · `git show id` · `git bisect` |

## 3. Git interview questions

1. **Git vs GitHub?** Git is the version control tool; GitHub is a website that hosts Git repositories and adds collaboration (PRs, issues, Actions).
2. **What is a commit?** A snapshot of the staged changes with an id, author, time, message and parent.
3. **What is the staging area?** Where you choose which changes go into the next commit.
4. **git pull vs git fetch?** fetch downloads; pull downloads and merges.
5. **merge vs rebase?** Merge keeps history with a merge commit; rebase replays commits for a linear history (don't rebase shared branches).
6. **reset vs revert?** reset moves the branch back (rewrites history); revert adds an undo commit (safe for shared branches).
7. **What is a merge conflict and how do you resolve it?** Both branches changed the same lines; edit the file, remove the markers, add, commit.
8. **What is HEAD?** A pointer to the commit/branch you're currently on.
9. **What does git stash do?** Saves uncommitted changes aside and cleans the working directory.
10. **What is .gitignore?** A list of files and patterns Git shouldn't track (dependencies, builds, secrets).
11. **What is a detached HEAD?** You've checked out a commit directly, not a branch; new commits aren't on any branch unless you create one.
12. **What is git bisect?** Binary search through history to find the commit that introduced a bug.
13. **What is cherry-pick?** Apply one specific commit from another branch onto the current branch.

## Common mistakes

- Long-lived branches that drift far from main.
- Mixing unrelated changes in one commit or PR.
- Not reading `git status` before committing.

## Quick recap

- Pull main → branch → small commits → push → PR → review → merge.
- Protected main, CI checks, squash merges, release tags.
- Know the 13 interview answers above.


Practice quiz and free certificate: https://skills101.in/learn/git/git-workflow-and-interview-questions