GIT REFERENCE · INTERVIEW & DAILY DEVOPS USE

GIT COMMAND MASTER MAP

From Beginner to Senior DevOps Engineer — every command mapped to where it actually operates in the Git lifecycle, not just listed alphabetically.

Starts here
Remote Repository
clone / pull
fetch
Zone 1
Working Directory
add
Zone 2
Staging / Index
commit
Zone 3
Local Repository
push
Zone 4
Remote Repository
Pull Request Code Review Merge CI/CD Deployment
Working Directory
Staging Area
Local Repository
Remote Repository
Debug / Advanced
Destructive — use with care
01Setup & Configurationone-time / global

Runs before any repository exists — configures Git itself.

git --version

Check installed Git version.

git config --global user.name "Name"

Configure your commit username.

git config --global user.email "email"

Configure your commit email.

git config --list

View current Git configuration.

git help <command>

Get help for any command.

02Create / Get a Repositorylocal repository

The two entry points into version control.

git init

Convert the current folder into a Git repository.

git clone <url>

Download an existing remote repository.

MEM
INIT = start new  ·  CLONE = copy existing
03Check Changesworking dirstaging

Inspect state before you act — the "what's going on" commands.

git status

What changed?

git diff

Show unstaged changes.

git diff --staged

Show staged changes.

git log

Commit history.

git log --oneline

Compact commit history.

git show <commit>

Inspect a single commit in detail.

MEM
STATUS=what?  DIFF=what's different?  LOG=what happened?  SHOW=show me that commit
04Stagingstaging area

Working Directory → Staging Area.

git add file.txt

Stage one file.

git add .

Stage everything.

git restore --staged file.txt

Remove a file from staging.

MEM
ADD = prepare for commit
05Commitlocal repository

Staging Area → Local Repository.

git commit -m "message"

Create a commit.

git commit -am "message"

Stage tracked files and commit in one step.

git commit --amend

Modify the previous commit.

MEM
COMMIT = local checkpoint
06Branchinglocal repository

Parallel lines of development inside the local repo.

git branch

List branches.

git branch feature/login

Create a branch.

git switch feature/login

Switch to a branch.

git switch -c feature/login

Create and switch in one step.

git checkout <branch>

Older way to switch branches.

git branch -d feature/login

Delete a merged branch.

git branch -D feature/login

Force-delete a branch.

MEM
BRANCH = parallel development  ·  SWITCH = move between branches
07Merginglocal repository

Combine two branch histories into one.

git merge feature/login

Merge a branch into the current branch.

git merge --abort

Cancel a conflicted merge.

main ─────A────B────────M \ / feature C────D───┘
MEM
MERGE = combine histories
08Remote Repositoriesremote

Local Repository ⇄ Remote Repository.

git remote -v

Show configured remotes.

git remote add origin <url>

Connect a remote repository.

git fetch

Download remote info WITHOUT merging.

git pull

Fetch + integrate remote changes.

git push

Upload commits.

git push -u origin branch

First push + set upstream tracking.

MEM
FETCH = download, don't integrate  ·  PULL = download + integrate  ·  PUSH = upload
09Undo / Recoveryworking dirlocal repo

The three most confused commands in Git — separated by exactly what they undo.

git restore file.txt

Discard working-directory changes.

git restore --staged file.txt

Unstage a file.

git revert <commit>

Create a new commit that reverses an old one.

git reset --soft HEAD~1

Remove commit, keep changes staged.

git reset HEAD~1

Remove commit, keep working changes.

git reset --hard HEAD~1

Remove commit AND changes — unrecoverable via normal means.

MEM
RESTORE = files  ·  RESET = move local history  ·  REVERT = safely undo committed history
git reset --hard — Destructive. Uncommitted and committed changes past this point can be permanently lost. Prefer revert on shared branches.
10Stashworking dir

Temporary shelf for unfinished changes.

git stash

Temporarily store unfinished changes.

git stash list

List stashes.

git stash pop

Restore + remove latest stash.

git stash apply

Restore but keep the stash.

git stash drop

Delete a stash.

MEM
STASH = temporary shelf
11Rebaselocal repository

Replay commits for a clean, linear history.

git rebase main

Replay commits on top of main.

git rebase -i HEAD~3

Interactive history cleanup.

git rebase --continue

Continue after resolving a conflict.

git rebase --abort

Cancel the rebase.

Before: main A──B──C \ feature D──E After rebase: main A──B──C──D'──E'
MEM
REBASE = replay / clean linear history
12Cherry-Picklocal repository

Copy one specific commit onto the current branch.

git cherry-pick <commit>

Copy one specific commit onto the current branch.

Branch A: A──B──C │ Branch B: D──E──C' ◄── copied
MEM
CHERRY-PICK = pick one commit
13Tagslocalremote

Mark release points in history.

git tag

List tags.

git tag v1.0

Create a lightweight tag.

git tag -a v1.0 -m "Release v1.0"

Create an annotated release tag.

git push origin v1.0

Push a single tag.

git push origin --tags

Push all tags.

MEM
TAG = release marker
14File Managementworking dir
git rm file.txt

Remove a tracked file.

git mv old.txt new.txt

Rename or move a tracked file.

.gitignore

Files Git should ignore entirely.

15Conflict Resolutionworking dirlocal repo

Triggered by pull / merge / rebase when histories collide.

CONFLICT
open conflicted files
choose / fix correct code
git add <file>
git commit (or rebase --continue)
<<<<<<< HEAD
current code
=======
incoming code
>>>>>>> feature
MEM
FIX → ADD → CONTINUE/COMMIT
16Debugging / Advanced Commandsforensics

For when something already went wrong.

git blame <file>

Who changed each line?

git bisect start

Binary-search which commit introduced a bug.

git reflog

History of HEAD movements — recover "lost" commits.

git clean -n

Preview untracked files that would be removed.

git clean -fd

Remove untracked files and directories — permanent.

MEM
BLAME = who changed it?  ·  BISECT = which commit broke it?  ·  REFLOG = where was HEAD?
git clean -fd — Destructive. Deletes untracked files/folders with no recovery path. Always run -n first.
17Daily DevOps Workflowend-to-end

What a typical feature ticket looks like in practice, clone to production.

git clone
git switch -c feature/JIRA-123
modify code
git status
git diff
git add .
git commit -m "JIRA-123: change"
git pull --rebase
git push -u origin feature/JIRA-123
Pull Request
Code Review
Merge
CI Pipeline — Build → Test → Security Scan
CD Pipeline — DEV → QA/UAT → PROD
18Most Important Memory Mapsummary

If you remember nothing else, remember this chain.

CREATE
init · clone
CHECK
status · diff · log
STAGE
add
SAVE
commit
SYNC
fetch · pull · push
COLLABORATE
branch · switch · merge · rebase
TEMPORARILY SAVE
stash
UNDO
restore · revert · reset
RECOVER / DEBUG
reflog · blame · bisect
RELEASE
tag
"Git is easier to remember when you understand WHERE a command acts."
Working DirectoryStagingLocal RepositoryRemote Repository
ADD → COMMIT → PUSH — the core save chain
FETCH — download only
PULL — download + integrate
STASH — temporary save
RESTORE — file undo
REVERT — safe commit undo
RESET — move history
REBASE — replay history
CHERRY-PICK — copy one commit
REFLOG — recover history