Interview Prep/Git & GitHub/Push, Pull and Fetch Errors

`You are not currently on a branch.` when running `git pull` or `git push`.

BeginnerTroubleshootingPush, Pull and Fetch Errors
Answer

Likely causes → HEAD is detached, usually after checking out a tag or commit, or in the middle of a rebase.

Diagnose → git status ("HEAD detached at ...") and git branch --show-current (empty).

Fix → To keep commits made here: git switch -c my-branch. To leave: git switch main. If a rebase is in progress, finish with git rebase --continue or abort.

Prevent → Use git switch -c before experimenting, and show the branch in your prompt.

All Git & GitHub questions Roadmap: Git & GitHub

More on Push, Pull and Fetch Errors