

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


MASTER EDITION
The Git Architecture Overview: Git manages files across three local areas: the Working Directory (untracked/modified files), the Staging Area/Index (prepared for commit), and the Local Repository (committed snapshots). Remote repositories extend this workflow to teams.
Working Directory Local modified files
Unstaged
Staging Area (Index) Prepared changes
Index
Local Repository Committed HEAD (.git)
Local Commits
Remote Repo GitHub / GitLab
origin/main
git add commit push
fetch / pull
git config --global user.name "[name]" Sets author name attached to all local commits.
git config --global user.email "[email]" Sets author email address attached to local commits.
git config --global core.editor "[editor]" Configures default text editor (e.g., code --wait , vim ).
git config --global init.defaultBranch main Sets default branch name to 'main' for newly initialized repositories.
git config --list Lists all global and repository-level configurations.
git init Initializes a new Git repository in the current working directory.
git init [project-name] Creates a new folder and initializes an empty Git repository inside it.
git clone [url] Downloads full repository, history, and branches from remote host.
git clone --depth 1 [url] Shallow clone: downloads only the latest commit (saves bandwidth/time).
git status Shows state of working tree (tracked, untracked, modified, staged).
git status -s Displays status in compact short-format.
git add [file] Stages a specific^ file for the next commit.
git add. Stages all modified, new, and deleted^ files in current directory tree.
git add -p Interactive patch mode: select specific hunks of changes to stage.
git commit -m "[message]" Records staged snapshot permanently in version history with message.
4. BRANCHING & CONTEXT SWITCHING
git branch Lists all local branches. Current active branch marked with an asterisk (*).
git branch -a Lists all local AND remote-tracking branches.
git branch [branch-name] Creates a new branch pointer at current HEAD commit without switching.
git switch [branch-name] Switches to target branch (Modern alternative to git checkout ).
git switch -c [branch-name] Creates and immediately switches to new branch.
git branch -d [branch-name] Deletes specified branch safely (refuses if unmerged changes exist).
git branch -D [branch-name] Force deletes a branch regardless of merge status. Use caution.
git branch -m [new-name] Renames the currently active branch.
5. MERGING, REBASING & HISTORY CLEAN-UP
git merge [branch] Merges named branch into current branch, creating a merge commit.
git merge --no-ff [branch] Forces a explicit merge commit even if fast-forward is possible.
git rebase [base-branch] Re-applies current branch commits on top of [base-branch] for linear history.
git rebase -i HEAD~[N] Interactive rebase for last N commits: squash, reword,^ fixup, or drop commits.
git rebase --abort Cancels an in-progress rebase operation and restores original state.
git cherry-pick [commit-hash] Applies changes introduced by specific commit to current branch.
Golden Rule of Rebasing: Never rebase commits that have already been pushed to a shared public repository. Rebasing rewrites commit hashes and will create divergent histories for team members.
6. INSPECTION, LOGS & DIFF ANALYSIS
git log Displays commit history in reverse chronological order.
git log --oneline --graph --all Displays condensed ASCII visual branch graph of all commits.
git log -p -n [count] Shows diff patch output for the last N commits.
git diff Shows unstaged changes between working directory and staging index.
git diff --staged Shows staged changes prepared for commit vs. last commit.
git diff branchA..branchB Displays line-by-line differences between two branches.
git blame [file] Annotates each line of^ file with commit hash, author, and timestamp.