0% found this document useful (0 votes)
6 views20 pages

Git Version Control Field Manual

The document is a comprehensive 'Field Manual' for using Git, detailing essential commands, workflows, and strategies for version control. It includes a command dictionary, visual workflow explanations, and troubleshooting scenarios to aid users in understanding and applying Git effectively. Key concepts covered include command syntax, explanations, risk levels, and practical usage patterns for various Git operations.

Uploaded by

muskan.s.khan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views20 pages

Git Version Control Field Manual

The document is a comprehensive 'Field Manual' for using Git, detailing essential commands, workflows, and strategies for version control. It includes a command dictionary, visual workflow explanations, and troubleshooting scenarios to aid users in understanding and applying Git effectively. Key concepts covered include command syntax, explanations, risk levels, and practical usage patterns for various Git operations.

Uploaded by

muskan.s.khan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

The Version Control "Field Manual"

Objective: Create a comprehensive "Field Manual" that explains not just the
what (commands), but the how and why (workflows and strategies) of using

Git. This document should be written clearly enough to serve as a learning

resource for you in your projects.

Module 1: The Command Dictionary

Goal: Build a quick-reference guide for essential Git commands.

Instructions: Research the following commands. Create a table with the


columns listed below. Do not just copy-paste official documentation; rewrite

the "Explanation" in your own words.

Required Table Columns:

1. Command Name

2. Basic Syntax (e.g., git commit -m "message")

3. Plain English Explanation (What does it actually do?)

4. When to Use It (In what situation do you run this?)

5. Risk Level (Safe vs. Destructive/Can lose data)

Commands to Document:

● Setup: git config, git init, git clone

● Staging & Saving: git status, git add, git commit, git diff

● Branching: git branch, git checkout, git switch, git merge


● Syncing: git fetch, git pull, git push

● History: git log, git show, git blame

● Undo/Fix: git stash, git reset, git revert

Sol.

Setup

Command Basic Syntax Explanation When to Use Risk Level


Name

git config git config Configures Initially setting Safe


--global Git's global or up Git on a
local machine, or
[Link]
preferences, when you need
"Your Name"
such as your to update
or git identity (name default settings
config -- and email), (e.g., name,
global preferred email, or
[Link] editor, etc. The default branch
"you@exampl --global flag name).
[Link]" applies the
settings to all
repositories.

git init git init Initializes a To start Safe (but can


new, empty Git tracking an be confusing if
repository in existing project
you run it
the current folder that is
directory by not yet under inside an
adding a .git version control. already-tracked
subdirectory. repo or nested
directories)
git clone git clone Creates a local When you Safe
<URL> copy of a need to retrieve
remote the code and
[target-
repository, full history from
dir]
including its a remote
entire history. source (like
GitHub, GitLab)

Staging & Saving

Comm Basic Plain English When to Use It Risk Level


and Syntax Explanation
Name

git git Shows what’s Frequently, to Safe


status status changed, understand
what’s what’s pending
staged, and before
which branch committing or
you’re on. switching
branches.

git add git add Puts changes Before Safe (but


/ git into the committing; to be mindful:
add . “staging select exactly git add .
area” so the which changes can stage
next commit go into a unintended
includes commit. files)
them.

git git Saves staged After staging Safe


commi commi changes into changes that
t t -m history with a logically belong
"messa message. together.
ge" / Without -m,
git opens editor
commi for a detailed
t message.

git diff git Shows line- To review Safe


diff / by-line changes before
git diff differences. staging/committ
-- Default ing, or to
staged compares compare
/ git working copy branches/comm
diff vs. index; -- its.
staged
compares
index vs. last
commit;
comparing
refs shows
differences
across
history.

Branching

Comman Basic Plain English When to Use It Risk Level


d Name Syntax Explanation

git git Lists branches; Creating topic Safe (deleting


branch branch / creates or branches for with -d is safe
git deletes a features/bugfixes; if merged; use
branch / branch pointer. cleaning up old -D cautiously
git It doesn’t branches. —Destructive)
branch - switch you; it
d just manages
branches.

git git Switches Switching Mixed


checkout checkout branches or branches; creating (switching is
/ git restores files. -b a branch quickly; Safe; restoring
checkout creates and discarding local files with -- is
-b / git switches to a changes to Destructive to
checkout new branch. -- specific files. uncommitted
-- <file> changes)
discards
changes to a
file by restoring
from HEAD.

git git switch A newer, Prefer this over Safe


switch / git simpler way to checkout for
switch -c change branch switching
branches (it’s clearer/safer).
without the file-
restore
behavior of
checkout. -c
creates and
switches to a
new branch.
git git Combines the When integrating Safe (can
merge merge specified completed work cause
branch into from another conflicts you
your current branch (feature → must resolve;
branch. main or updating history
Creates a your feature from changes are
merge commit main). additive)
if needed; fast-
forwards if
possible.

Syncing (Remote Collaboration)

Comman Basic Plain English When to Use It Risk Level


d Name Syntax Explanation

git fetch git fetch Downloads new To see what’s Safe


[remote] commits/refs new on the
[branch] from the remote, remote without
but doesn’t changing local
change your files; before
working branch. reviewing
incoming work.

git pull git pull / Fetches, then To update your Mixed (can
git pull -- integrates branch with the cause merge
rebase changes into latest remote conflicts; --
your current changes. Use -- rebase
branch (merge rebase to keep a rewrites your
by default, or clean, linear local commits
rebase with -- history (team —be cautious)
rebase). policy-
dependent).

git push git push Uploads your When sharing Mixed


[remote] local commits to your work or (pushing is
[branch] the remote. -u publishing a Safe; force-
/ git push sets upstream branch. pushing -f/--
-u origin tracking for force is
future Destructive to
pulls/pushes. shared
history)

History

Comman Basic Plain English When to Use Risk Level


d Name Syntax Explanation It

git log git log / Shows commit To explore Safe


git log -- history. Options history,
oneline -- help visualize understand
graph -- branches and branch
decorate simplify output. topology, or
--all find specific
changes.

git show git show / Displays details Inspecting a Safe


git show : of a commit specific
(message, diff). commit or
With viewing a file
<commit>:<path as it was at a
>, shows a file’s point in time.
content at that
commit.

git blame git blame Shows line-by- To find Safe (use


line authorship who/when a thoughtfully;
and the commit line changed pair with git
that last for log -L and
changed each debugging, discussions
line. ownership, or rather than
context. finger-pointing)

Undo / Fix

Comman Basic Plain English When to Use It Risk Level


d Name Syntax Explanation

git stash git stash Temporarily Pausing work Safe (but


/ git shelves your quickly—e.g., to stashes can
stash - uncommitted fix something be lost if not
u / git changes so you elsewhere— applied; -u
stash list can switch without stashes more
/ git branches or pull committing. content—
stash cleanly. -u includes know what
apply / untracked files. you’re
git stash apply replays shelving)
pop without removal;
pop replays and
removes from
stash.

git reset git reset Moves the current Rewriting local Destructive
--soft / branch pointer to a history or (especially --
git reset different commit. undoing hard; also
-- --soft keeps commits. Use risky if applied
mixed / changes staged; --soft to to pushed
git reset --mixed (default) rework a commits)
--hard keeps changes in commit; --hard
working area; -- to throw away
hard discards changes. Never
changes. hard-reset
shared history.

git revert git revert Creates a new Safely undo a Safe (may
commit that bad commit in require
undoes the a shared conflict
changes of the branch (no resolution if
specified commit, rewrite). the original
preserving history. commit
touched
many areas)
Quick Usage Patterns (Workflow Tips)

● Daily Flow:
git status → git add (selective) → git commit -m "Clear message"
→ git pull --rebase (if team prefers) → resolve conflicts if any → git
push.
● Feature Branching:
git switch -c feature/xyz → work & commit → git push -u origin
feature/xyz → open PR → after review, git merge via platform → delete
local branch: git branch -d feature/xyz.
● Safe Undo:
Use git revert on shared branches; use git reset on your local,
unpushed commits only.
● Review Before Commit:
git diff (unstaged) and git diff --staged (what you’re about to
commit).
● Stay in Sync:
git fetch regularly; git pull when ready to integrate.

Risk Legend

● Safe: Read-only or additive; won’t destroy local work.


● Mixed: Can be safe, but context matters (rebase, merge conflicts,
overwriting).
● Destructive: Can permanently discard changes or rewrite history; use
with caution.

Module 2: Visualizing the Workflow


Goal: Demonstrate understanding of the data flow between

different Git areas.


Instructions: Version control moves files between four specific "zones."
Create a visual diagram (or a detailed text-based flow) illustrating how code

moves through these zones.

Key Concepts to Cover:

1. Working Directory (Where you edit files)

2. Staging Area / Index (Where you prepare files)

3. Local Repository (Your private history)

4. Remote Repository (The shared team history)

Deliverable:

● A diagram or step-by-step description showing which commands

move code from one zone to another (e.g., Which command moves

code from Working Directory -> Staging Area?).

Sol.
Flow Explanation: How Code Moves Through Git Zones

1. Working Directory → Staging Area

○ Command: git add <file>

○ Action: Takes modified files from your working directory and

places them in the staging area (index). This means you’re

preparing them for the next commit.

2. Staging Area → Local Repository

○ Command: git commit -m "message"

○ Action: Creates a snapshot of the staged changes and saves it in

your local repository as a commit. This is your private history.

3. Local Repository → Remote Repository


○ Command: git push origin <branch>

○ Action: Sends your local commits to the remote repository so

others can access them. This updates the shared team history.

4. Remote Repository → Local Repository

○ Command: git fetch or git pull

○ Action: Brings changes from the remote repository into your local

repository. git fetch only downloads, while git pull downloads

and merges (or rebases).

Reverse Flows (Undo or Move Backwards)

● Local Repository → Staging Area: git reset --soft <commit> (moves

HEAD back but keeps changes staged).

● Staging Area → Working Directory: git reset <file> (unstages a file).

● Working Directory (discard changes): git checkout -- <file> or git

restore <file> (reverts file to last committed state).

Module 3: The "Scenario Doctor" (Troubleshooting) Goal: Apply

your research to solve common problems without running code.

Instructions:

Imagine a colleague comes to you with the following issues. Research the

situation and write down the solution steps and the commands needed to fix

it.
Scenarios:

1. The "Premature" Switch: "I'm working on a bug fix, but I need to switch

branches to review someone else's code. I'm not ready to commit my

work yet. How do I save my work temporarily without committing?"

2. The Wrong Message: "I just committed my code, but I realized I made a

typo in the commit message. How do I fix the message without

creating a new commit?"

3. The Oops Delete: "I accidentally deleted a critical file ([Link]) from my

folder, but I haven't committed the deletion yet. How do I get the file

back?"

4. The Detached Head: "I checked out a specific commit ID to look at old

code, and now Git says I am in a 'detached HEAD' state. How do I get

back to my normal development state?"

Sol.

1) The “Premature” Switch

Problem: You’re in the middle of a bug fix but need to switch branches to

review someone else’s work. You’re not ready to commit.

Solution: Use a stash to shelve uncommitted changes, switch, then restore

them later.

Steps:

1. Stash your current changes (include untracked files if needed).


2. Switch to the other branch and review.

3. Return to your original branch and reapply the stash.

Commands:

# Save changes (tracked files)


git stash

# OR include untracked files as well


git stash -u # or: git stash --include-untracked

# Switch to the branch you want to review


git switch other-branch

# ...review work...

# Return to your bugfix branch


git switch bugfix-branch

# Reapply the stashed changes and remove the stash entry


git stash pop

# (If you prefer to keep the stash entry, use 'git stash apply' instead of 'pop')

2) The Wrong Message

Problem: You committed, but your commit message has a typo.

Solution: Amend the last commit message.

⚠️If the commit has already been pushed, coordinate with your

team before amending and force-pushing.

Commands:
# Open editor to edit the last commit message
git commit --amend

# Or provide the corrected message directly


git commit --amend -m "Correct, clear subject line"

3) The Oops Delete

Problem: You accidentally deleted [Link] locally but haven’t committed

that deletion.

Solution: Restore the file from the last committed version (HEAD).

Commands:

# If the file existed in the last commit:


git restore [Link]

# Older Git (or alternate syntax):


git checkout -- [Link]

4) The Detached HEAD

Problem: You checked out a specific commit (not a branch) and now Git says

you’re in detached HEAD.

Solution: Switch back to a branch (e.g., main) or create a new branch from the

current commit if you need to keep changes.

Commands:
# Return to normal (attach HEAD to a branch)
git switch main

#If you want to keep work you did while detached:

Module 4: Best Practices & Etiquette

Goal: Understand the "Social" side of Version Control.

Instructions: Research and compile a list of "The 5 Commandments of


Git." These should be rules that ensure the team works together smoothly.

Topics to Research:

● Commit Messages: What is the structure of a professional commit

message? (Subject vs. Body).

● Commit Frequency: Should you commit once a week or multiple times a

day? Why?

● Branch Naming: What are common conventions for naming branches?

(e.g., feature/, bugfix/).

● The ".gitignore" File: What is this file and what kind of files should always

go in here?

Submission Guidelines

● Format: Pdf

● Use clear headings, code blocks for commands, and bold text for

emphasis.
Sol.

1) Write Professional Commit Messages

● Subject line: 50 characters max; imperative mood; summarize what

and why.

● Blank line after subject.

● Body (optional): Explain why and context, reference issues/PRs, note

risks or follow-ups.

Example:

Fix login redirect when token expires

Explain that the redirect now goes to /auth/renew and


preserves the return URL.

2) Commit in Small, Logical Chunks

● Prefer multiple small commits per day over one giant weekly commit.

● Each commit should compile/test and represent a single logical

change.

● Benefits: clearer history, easier reviews, simpler rollbacks, fewer conflicts.

3) Use Clear Branch Naming

● Prefix by purpose/type:

○ feature/<short-name> — new functionality


○ bugfix/<ticket-id-or-short-name> — non-critical fixes

○ hotfix/<issue> — urgent fix on production

○ chore/<task> — maintenance, tooling, deps

● Use kebab-case or slashes; keep names short and descriptive.

● Example: feature/payment-retry, bugfix/1234-null-pointer,

hotfix/ssl-expiry.

4) Maintain a Proper .gitignore

● Keep noisy and sensitive files out of version control:

○ Build artifacts: dist/, build/, out/

○ Dependencies: node_modules/, .venv/, vendor/

○ Logs & temp: *.log, *.tmp, coverage/

○ Secrets & local config: .env, *.key, *.pem, *.sqlite

● Start from language/framework templates and tailor to your project.

Example:

# Dependencies & builds


node_modules/
dist/
build/

# Logs & coverage


*.log
coverage/

# Env & secrets


.env
*.pem


5) Collaborate Responsibly

● Pull (or fetch) before push to avoid overwriting teammates’ work.

● Prefer git pull --rebase on feature branches if your team uses a

linear history.

● Avoid --force on shared branches; if necessary, communicate and

coordinate.

● Use PRs, code reviews, and descriptive messages; link issues; keep

discussions friendly and constructive.

Common questions

Powered by AI

'Git branch -D' is a forceful deletion command that removes a branch, irrespective of whether it is fully merged. This action is necessary when a branch is deemed unnecessary or if the work it represents is conclusively terminated or obsoleted. Before performing 'git branch -D', it is critical to ensure that any valuable work on the branch is either merged, backed-up, or archived. Conducting a thorough review of the branch’s status using 'git log', as well as confirming with team members that the branch can be safely deleted, is a necessary precaution. This avoids accidental loss of work and maintains project integrity .

A properly structured '.gitignore' file is crucial in managing a project's workspace by excluding files that are not meant for version control, thereby reducing clutter and preventing potentially sensitive data from being exposed. Files typically included are build artifacts (e.g., 'dist/', 'build/'), dependency directories (e.g., 'node_modules/'), logs (e.g., '*.log'), and any local configuration or secret files (e.g., '.env'). By excluding these files, the repository remains clean and focused on source code and relevant assets, preventing unnecessary merge conflicts and enhancing operational clarity during team collaborations. It also protects sensitive information from being inadvertently committed, which could pose security risks .

When encountering a 'Detached HEAD' state in Git, recommended strategies include switching back to a branch using 'git switch <branch>', or creating a new branch from the current commit if changes made in this state need to be preserved. A 'Detached HEAD' occurs when a commit is checked out directly rather than through a branch, which means new commits will not be associated with any branch and could be lost when switching branches. This state affects development workflows by isolating the changes from standard branch tracking, thereby necessitating careful management to ensure that valuable work is not inadvertently discarded .

The 'git add' command is used to transfer files from the working directory to the staging area, signifying that the changes are prepared for inclusion in the next commit. This action is critical in version control practices as it allows the developer to selectively include changes, facilitating granular control over what is committed to the project's history. It mitigates the risk of bundling unintended changes with intentional ones, ensuring only vetted modifications are recorded. Additionally, the strategic use of 'git add' helps in experimenting with multiple features or fixes concurrently by staging relevant changes before committing .

The 'git log' command is essential for investigating a project's history, providing detailed insights into the sequence and authorship of commits. It helps developers understand changes over time, identify the source of bugs, and track the evolution of features and fixes. Using options such as '--oneline', '--graph', '--decorate', and '--all' enhances clarity by visualizing branch structure and commit details succinctly. Best practices for using 'git log' include regular review of commit histories, filtering logs with specific criteria to find relevant information quickly, and inspecting specific commits for deep insights. These practices help maintain an accurate understanding of the project's development trajectory .

The 'git restore' command is used to discard changes in the working directory, reverting files to their last committed state, enhancing the ability to manage local modifications effectively. It is especially useful when deciding to abandon changes for restarting work from a known stable point. Best practices for using 'git restore' include: making sure that uncommitted work is backed up if necessary, as this command can lead to irreversible loss of changes; using it in the context of testing where no permanent record of temporary changes is required; and employing it alongside commands such as 'git stash' when more comprehensive local change management is required .

'Git switch' is a newer command introduced to provide a clearer and safer way to change branches compared to 'git checkout'. While 'git checkout' was a multipurpose command that not only switched branches but also restored files and performed various other tasks, it could be confusing and misused. 'Git switch' exclusively manages branch changes, reducing the risk of inadvertently affecting file states, which can happen when users misunderstand or misapply 'git checkout'. This specificity promotes smoother workflows and reduces errors, especially in collaborative settings where clarity in commands fosters better team coordination .

'Git fetch' and 'git pull' are commands for synchronizing changes from a remote repository, essential in collaborative workflows. 'Git fetch' updates the local metadata to reflect the current state of the remote repository without altering the working directory or the current branch. This command is ideal when a developer wants to review the remote changes first or integrate them selectively. On the other hand, 'git pull' combines 'git fetch' with 'git merge (or rebase)', actively integrating the fetched changes into the current branch. Teams should use 'git fetch' for cautious synchronization, allowing individual assessment of incoming updates and preventing unintended overwrites, while 'git pull' is suited for scenarios where immediate and automated integration is desirable, albeit with a higher risk of creating conflicts that require resolution .

In collaborative Git workflows, 'git revert' holds strategic importance due to its ability to reverse changes from a specific commit by creating a new commit that undoes the changes, while preserving the project's history and avoiding potential conflicts that arise from history rewriting. This is opposed to 'git reset', which alters the commit history and is not suitable for collaborative branches as it may cause discrepancies for teammates’ repositories. 'Git revert' is therefore recommended for maintaining data integrity and consistent project state when modifying shared branches. This approach enables teams to correct mistakes efficiently without disrupting others' workflows .

Commit message best practices play a crucial role in maintaining effective communication within a development team using Git. Clear and structured messages help team members quickly understand the nature and intent of changes, aiding in code reviews and history navigation. Best practices include keeping the subject line concise, using imperative mood, and providing context or rationale in the body if necessary. This approach ensures that every commit serves as a meaningful checkpoint in the project's history, facilitating issue tracking, rollback, and collaboration by making the purpose of changes instantly comprehensible .

You might also like