! [rejected] on Friday evening. A teammate pushed first, your push bounces, and the temptation is --force. In this module you learn why it happened, how to sync safely, and how to mark the exact commit that is version 1.2.0.
Course
Git Basics Course · Module 4 of 7 · Stage 2 "In a team"
Learn
Remotes and origin, fetch vs pull vs push, tracking branches, release tags
How
4 lessons on a clone of my-plugin: your main has an unpushed commit, a teammate already pushed theirs
Your laptop ↔ GitHub
flowchart LR
subgraph L["Your laptop"]
direction TB
M["main"]
OM["origin/main<br/>last known state"]
end
G[("GitHub<br/>origin")]
G -- "git fetch<br/>look, don't touch" --> OM
OM -- "merge / rebase" --> M
G -- "git pull<br/>= fetch + merge" --> M
M -- "git push" --> G
classDef local fill:#fff7ed,stroke:#EE5133,color:#7c2d12
classDef remote fill:#EE5133,stroke:#9a2a14,color:#ffffff
class M,OM local
class G remote
Which command, when
Situation
Command
See what the team pushed, change nothing
git fetch
Bring the team's work into your branch
git pull
"The current branch has no upstream branch"
git push -u origin <branch>
Push rejected after a rebase of your own branch
--force-with-lease, never plain --force
"Which commit is version 1.2.0?"
an annotated tag: git tag -a v1.2.0
You'll be able to answer
How is origin/main different from main?
What's the difference between fetch and pull?
Why is --force-with-lease safer than --force?
What's the difference between a lightweight and an annotated tag?