I'm only nine days into a new job and accidentally force-pushed over a coworker's branch after half-remembering a tutorial that made force-pushing sound like a general fix. We recovered the work from their local copy, and nobody got angry, but standup was painfully quiet. At the moment I mainly understand add, commit, and push. What concepts and commands should I learn next so I can understand branching, merging, and rebasing without putting shared work at risk?
3 Answers
The bigger lesson is not to run a command based on a half-remembered tutorial when other people’s work is involved. Ask someone on the team, check the repository’s contribution guide, and use a local test repository to confirm what a command does. A good progression is: commit and inspect history, create and switch branches, fetch and merge, resolve conflicts, then learn rebase and reflog. Also, your team should ideally have branch protection that blocks force-pushes to shared branches.
Don’t beat yourself up too much—many people learn Git by making mistakes. The safest next step is to practice in a throwaway local repository: create branches, make conflicting edits, merge them, try a rebase, resolve conflicts, abort the operation, and inspect the result with git log and git reflog. A backup branch such as git branch rebase-backup gives you a reference you can return to before experimenting. Learn the mental model first: commits are snapshots with parents, branches are movable references to commits, and rebasing creates new commits on a different base. Once that makes sense, the commands feel much less mysterious.
Treat force-push as an exceptional operation, not a normal repair command. Never use plain --force on a shared branch. If you are intentionally rewriting a branch you own and have permission to update, --force-with-lease is safer because it can reject the push when the remote changed since your last known state. It still rewrites history, though, so it does not make force-pushing harmless. Protected branches and permissions should also prevent accidental rewrites of important branches.
The lease only protects against a specific race: someone pushing after your last remote update. It does not make rewriting shared history acceptable, so team approval and branch protections are still essential.

The important part is practicing somewhere that cannot affect coworkers. If a rebase goes badly, git rebase --abort usually returns the branch to its starting point, and reflog can often help recover earlier positions.