17 entries
How to use this reference
Use this as a reference, not a script to run from top to bottom. Replace example names and paths. Commands operate in the current repository unless --global is shown. Review git status before commands that change files.
Configure
Inspect effective configuration
Shows values and where they came from. Avoid sharing output that includes private URLs or credentials.
git config --list --show-originSet author identity
These global settings affect future commits in all repositories unless overridden locally. Use your intended public or GitHub no-reply email.
git config --global user.name "Your Name"
git config --global user.email "you@example.com"Retrieve a repository
Clone and enter
Creates a new local directory and an origin remote; replace the URL with your project.
git clone https://github.com/OWNER/REPOSITORY.git
cd REPOSITORY
git remote -vDaily change cycle
1. Inspect the working tree
Shows the current branch, staged files and unstaged changes. It changes nothing.
git status --short --branch
git diff2. Stage only intended files
Review the staged diff before committing. Avoid git add . when unrelated changes or secrets may be present.
git add README.md
git diff --cached3. Commit locally
Creates a commit from the index, not every modified file. This does not publish anything.
git commit -m "docs: clarify setup instructions"4. Publish your branch
Uploads local commits and sets the tracking branch. Confirm origin is your intended writable repository.
git push -u origin my-featureSynchronise
Inspect before integrating
Fetch updates remote-tracking references without merging into your working branch.
git fetch origin
git log --oneline HEAD..origin/mainFast-forward your local branch
Use on the intended branch with a clean working tree. This refuses divergent history rather than creating an unexpected merge. Replace main if the project uses another base.
git switch main
git pull --ff-only origin mainBranches
List branches
The asterisk identifies the current branch; -a includes remote-tracking references.
git branch
git branch -r
git branch -aCreate and switch
Starts from the current commit. git switch -c requires a Git version supporting switch; older Git can use git checkout -b.
git switch -c my-featureSwitch to an existing branch
Save or commit intended work first; Git may refuse a switch that would overwrite changes.
git switch my-featureDelete a merged local branch
Run from a different branch after confirming the work is merged. -d refuses some unmerged deletions; do not replace it with -D merely to silence that safeguard.
git branch -d my-featurePreview remote branch deletion
Remote deletion affects collaborators. This is a dry run; agree on deletion and verify the remote before deliberately removing --dry-run.
git push --dry-run origin --delete my-featureDiagnose
Read history and patches
Both commands are read-only. The first gives a graph, the second the latest commit's patch.
git --no-pager log --graph --oneline --decorate -n 20
git --no-pager log -p -n 1List changed files
The first lists unstaged changes; the second lists staged changes.
git diff --name-only
git diff --cached --name-onlyOpen the graphical history viewer
Optional desktop tool; it requires a working gitk installation and GUI session.
gitk --all