Pushing and Pulling
Asha committed a new soup recipe on her laptop. Ravi committed his dal recipe on his. Neither can see the other's work yet, because commits live in each person's own repository until they are sent or received. Push sends; pull receives.
The rule
Push sends your commits up; pull brings theirs down and merges them in.
Pushing uploads commits from a local branch to the matching branch on a remote:
git push -u origin main # first time: push and remember origin/main as upstream
git push # afterwards: the upstream is remembered-u (short for --set-upstream) links your local main to origin/main, so later a plain git push or git pull knows where to go. A new branch needs its own first push: git push -u origin vegan-pancakes.
Push sends commits only. Uncommitted edits and unstaged files stay on your machine.
Pulling downloads new commits from the remote and merges them into your current branch:
git pullUnder the hood, git pull is two steps: git fetch (download) followed by git merge (combine). So everything from the merging lesson applies: it can fast-forward, create a merge commit, or stop with a conflict for you to resolve. Some teams configure pull to rebase instead of merge, a choice that belongs to more advanced Git work. Recent versions of Git ask you to make this choice once, and refuse to pull diverged branches until you do. To get the merging behaviour this course uses, run:
git config --global pull.rebase falseRejected pushes. If the remote branch has commits you do not have, Git refuses your push:
! [rejected] main -> main (fetch first)
error: failed to push some refsThis is Git protecting other people's work. Pushing would throw their commits away. The fix is to pull first, combine the histories, then push.