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

Link to this task

Shows values and where they came from. Avoid sharing output that includes private URLs or credentials.

bash
git config --list --show-origin

Set author identity

Link to this task

These global settings affect future commits in all repositories unless overridden locally. Use your intended public or GitHub no-reply email.

bash
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
Retrieve a repository

Clone and enter

Link to this task

Creates a new local directory and an origin remote; replace the URL with your project.

bash
git clone https://github.com/OWNER/REPOSITORY.git
cd REPOSITORY
git remote -v
Daily change cycle

1. Inspect the working tree

Link to this task

Shows the current branch, staged files and unstaged changes. It changes nothing.

bash
git status --short --branch
git diff

2. Stage only intended files

Link to this task

Review the staged diff before committing. Avoid git add . when unrelated changes or secrets may be present.

bash
git add README.md
git diff --cached

3. Commit locally

Link to this task

Creates a commit from the index, not every modified file. This does not publish anything.

bash
git commit -m "docs: clarify setup instructions"

4. Publish your branch

Link to this task

Uploads local commits and sets the tracking branch. Confirm origin is your intended writable repository.

bash
git push -u origin my-feature
Synchronise

Inspect before integrating

Link to this task

Fetch updates remote-tracking references without merging into your working branch.

bash
git fetch origin
git log --oneline HEAD..origin/main

Fast-forward your local branch

Link to this task

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.

bash
git switch main
git pull --ff-only origin main
Branches

List branches

Link to this task

The asterisk identifies the current branch; -a includes remote-tracking references.

bash
git branch
git branch -r
git branch -a

Create and switch

Link to this task

Starts from the current commit. git switch -c requires a Git version supporting switch; older Git can use git checkout -b.

bash
git switch -c my-feature

Switch to an existing branch

Link to this task

Save or commit intended work first; Git may refuse a switch that would overwrite changes.

bash
git switch my-feature

Delete a merged local branch

Link to this task

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.

bash
git branch -d my-feature

Preview remote branch deletion

Link to this task

Remote deletion affects collaborators. This is a dry run; agree on deletion and verify the remote before deliberately removing --dry-run.

bash
git push --dry-run origin --delete my-feature
Diagnose

Read history and patches

Link to this task

Both commands are read-only. The first gives a graph, the second the latest commit's patch.

bash
git --no-pager log --graph --oneline --decorate -n 20
git --no-pager log -p -n 1

List changed files

Link to this task

The first lists unstaged changes; the second lists staged changes.

bash
git diff --name-only
git diff --cached --name-only

Open the graphical history viewer

Link to this task

Optional desktop tool; it requires a working gitk installation and GUI session.

bash
gitk --all