For mistakes that have already entered shared history, rewriting tools are needed. To remove a committed secret, use git filter-repo or the BFG Repo-Cleaner to scrub it from every commit, then force-push and rotate the secret itself. Such operations rewrite every commit's hash, so every collaborator must re-clone or carefully reset. To start over on a feature branch while keeping its name, git switch --orphan feature && git rm -rf . creates an orphan branch with no history and no files, ready for a fresh first commit. To recover a deleted branch, git reflog finds its last tip and git switch -c branchname <sha> resurrects it; the same trick, git checkout -b rescue <sha>, rescues a commit you thought was lost.
Working with forks introduces the "upstream" remote: git remote add upstream URL && git fetch upstream adds the original repository; then git switch main && git fetch upstream && git rebase upstream/main && git push origin main updates your fork's main branch with the latest upstream changes. Shallow clones speed up CI at the cost of history. git clone --depth 1 URL fetches only the most recent commit, while git clone --branch main --single-branch URL restricts the clone to one branch. If you later need full history on a shallow clone, git fetch --unshallow retrieves the rest. For monorepos where you only need a subset of folders, git sparse-checkout init --cone followed by git sparse-checkout set folder1 folder2 materializes only the specified paths after the initial clone. Submodules embed another repository at a path; the basics are git submodule add URL path, git submodule update --init --recursive, and remembering that the parent repository only tracks the submodule's pinned SHA, not its contents.
Configuration and a few quality-of-life flags tie things together. Local config lives in .git/config and is set with git config user.email 'work@example.com'; global config lives in ~/.gitconfig and is set with --global. git config --list --show-origin displays every setting and the file it comes from. Line-ending normalization trips up Windows users; setting core.autocrlf together with a .gitattributes file containing text=auto eol=lf keeps the working tree consistent. On cross-platform projects, core.ignorecase true makes file name matching case-insensitive, though this can hide real case bugs. Other useful flags include pull.rebase true to make pulls rebase by default, rerere.enabled true to remember conflict resolutions, and commit.gpgsign true with user.signingkey set to sign commits with GPG. Finally, periodic maintenance such as git gc (or git gc --aggressive --prune=now) reclaims space and keeps the object database healthy.