Reference

Git

Inspect, save, combine and recover work with clear command effects.

Scope and conventions

Modern Git CLI, including switch and restore (Git 2.23+). Independent examples use illustrative paths and branch names. Inspect status and diffs before changing files or history. Commands below are reference material, not executed by this guide.

Workspace & policy

Ignore untracked generated files

Git

.gitignore affects intentionally untracked files. It does not untrack a file already in the index.

Fragment

Git · Ignore untracked generated files
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
git check-ignore -v -- build/output.js
git ls-files -- build/output.js
# To stop tracking an intended path:
git rm --cached -- build/output.js

--cached removes the index entry and keeps the working file. Commit the policy change deliberately.

Temporarily store local changes

Git

stash push stores tracked staged/unstaged changes; -u also includes untracked files. apply retains the stash; pop drops it only after a successful application.

Fragment

Git · Temporarily store local changes
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
git stash push -u -m "input experiment"
git stash list
git stash show -p 'stash@{0}'
git stash apply 'stash@{0}'

Ignored files need -a, which can capture large generated content. Applying may conflict; --index attempts to restore staging too.

Use a second working directory

Git

A worktree has its own checked-out files and index while sharing repository objects and most refs. Normally the same branch cannot be checked out in two worktrees.

Fragment

Git · Use a second working directory
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
git worktree add -b review/input ../input-review main
git worktree list

A worktree lets another task stay separate without stashing the first task.

Preview untracked-file removal

Git

clean -n previews removal. -d includes untracked directories; -x includes ignored files. Preview scope before considering a real deletion.

Fragment

Git · Preview untracked-file removal
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
git clean -nd
git clean -ndx

These examples only preview. A later -f deletion is not preserved in commit history.

Inspect configuration and commit identity

Git

--show-origin identifies which configuration file supplied each setting. --local scopes identity to the current repository.

Fragment

Git · Inspect configuration and commit identity
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
git config --list --show-origin
git config --local user.name "Example Developer"

Names and email identify commits; they do not establish authentication or authorization.

Clone a repository or initialize your own

Git

clone creates a local repository from an existing one, normally configures origin and checks out its initial branch. init creates repository metadata in a new or existing directory; it does not upload files.

Fragment

Git · Clone a repository or initialize your own
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
git clone https://example.test/team/project.git

# Alternative: start a separate repository.
mkdir new-project
cd new-project
git init -b main

The clone URL is illustrative. init -b requires Git 2.28+. These are alternative starting points.

Read ignore patterns

Git

A trailing / targets directories. A slash at the start or in the middle anchors a pattern to its ignore file’s directory; a pattern with no other slash matches at any depth. ! negates a rule; an excluded parent directory prevents Git from discovering a re-included child.

Fragment

Git · Read ignore patterns
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
# .gitignore example:
/build/
*.log
!important.log
.env.local

Ignore files are not a secret-protection mechanism and do not stop tracking existing index entries.