What is the difference between origin/main and main in Git?
Answer
main is your local branch — the branch pointer in your local repository that moves when you make commits. origin/main is a remote-tracking branch — a read-only local reference that represents the last known state of main on the remote named "origin." It is updated only when you run git fetch, git pull, or git push. The two can diverge: you commit locally → main advances, origin/main stays; someone pushes to remote → after git fetch, origin/main advances, local main stays. Commands: git log main..origin/main — commits on remote not yet local (remote is ahead); git log origin/main..main — commits local not yet on remote (local is ahead); git diff main origin/main — see differences. git branch -vv — shows tracking relationships and ahead/behind counts. git status also shows "Your branch is behind origin/main by 3 commits." Tracking setup: when you git clone, local main automatically tracks origin/main. For new local branches: git push -u origin feature sets the tracking relationship.