Git & GitHub Command Reference
Operational reference for core Git commands, workflows, and execution contexts.
This document defines the practical command surface of Git and where each command operates in the repository lifecycle.
Problem Context
Git workflows often fail due to misuse of commands across different repository zones.
Common issues:
- Committing unintended changes
- Losing work during resets
- Confusion between local and remote state
- Improper branch handling
Understanding command scope and execution context is required for safe operation.
Architecture Overview
Git operates across three primary zones:
- Working Directory — file edits
- Staging Area — change preparation
- Local Repository — committed history
- Remote Repository — shared state
Each command affects one or more of these zones.
Lifecycle Flow
Core Commands by Zone
Repository Initialization
git init
Initializes a new local repository.
git init
Where it operates
- Creates
.gitdirectory - Does NOT track files automatically
- Affects local repository only
Typical use
- Starting a new project
- Converting an existing folder into a repo
Cloning
git clone
Creates a full local copy of a remote repository.
git clone <repo-url>
Where it operates
- Creates working directory
- Creates local repository
- Configures remote origin
Typical use
- Onboarding to an existing project
- Creating distributed copies
Staging Changes
git add
Moves changes from working directory to staging area.
git add <file>
Add all files:
git add .
Where it operates
- Working Directory → Staging Area
- Does NOT create commits
Typical use
- Preparing specific files for commit
- Building atomic commits
Checking Status
git status
Shows current repository state.
git status
Where it operates
-
Read-only inspection
-
Shows:
- Untracked files
- Modified files
- Staged files
Typical use
- Before committing
- During conflict resolution
Creating Commits
git commit
Creates an immutable snapshot from staged changes.
git commit -m "message"
Where it operates
- Staging Area → Local Repository
- Generates SHA-1 commit
Typical use
- Recording logical changes
- Creating history checkpoints
Branch Management
List branches
git branch
Create branch
git branch <branch-name>
Switch branch
git checkout <branch-name>
Create and switch:
git checkout -b <branch-name>
Delete branch
git branch -d <branch-name>
Where it operates
- Local repository metadata
- Working directory context
Typical use
- Feature isolation
- Parallel development
Remote Configuration
View remote
git remote -v
Add remote
git remote add origin <repo-url>
Remove remote
git remote remove origin
Where it operates
- Local repository config
- Does not move code
Fetching
git fetch
Downloads remote changes without merging.
git fetch
Where it operates
- Remote → Local repository
- Working directory unchanged
Typical use
- Safe remote inspection
- Pre-merge review
Pulling
git pull
Fetches and merges remote changes.
git pull
Where it operates
- Remote → Local repository
- Local repository → Working Directory
Typical use
- Synchronizing with team
- Updating local branch
Pushing
git push
Uploads local commits to remote.
git push origin <branch>
Where it operates
- Local repository → Remote repository
Typical use
- Sharing changes
- Triggering CI/CD
Conflict Resolution Commands
Inspect merge conflicts
git log --merge
git diff
Abort merge
git merge --abort
Reset conflicted files
git reset
Operational note
Conflicts must be manually resolved before committing.
Stash Workflow
Temporary storage for unfinished work.
Stash changes
git stash
List stashes
git stash list
Apply stash
git stash apply
Pop stash
git stash pop
Drop stash
git stash drop
Stash Flow
History Manipulation
Cherry Pick
Apply a specific commit to current branch.
git cherry-pick <commit-hash>
Use carefully
- Creates new commit hash
- Can duplicate history
Rebase
Replay commits on a new base.
git rebase <branch>
Primary goal
- Maintain linear history
Risk
- Rewriting shared history
Squash via Interactive Rebase
git rebase -i HEAD~n
Use case
- Combine multiple commits
- Clean PR history
Implementation Notes
- Always review
git statusbefore commit - Prefer
fetchbeforepullin critical systems - Avoid force push on shared branches
- Keep commits small and atomic
- Use branches per feature
Operational Considerations
Failure Modes
- Hard reset can destroy uncommitted work
- Force push rewrites shared history
- Stash is local only (not backed up)
- Long-lived branches increase conflicts
Scaling Notes
- Enable branch protection
- Use CI on push
- Periodically prune stale branches
- Avoid committing large binaries
Data Safety
- Remote is not a true backup
- Protect main branch
- Use meaningful commit messages
- Tag release points
Conclusion
Git reliability depends on correct command usage within the repository lifecycle. Understanding command scope prevents data loss and maintains clean collaborative history.