Lesson 12
Push
Push publishes commits from your local branch to a branch in a remote repository.
Visual Explanation
Ready to run git push -u origin feature/login.
Keep These Ideas
- Publish commits
- Push sends saved history, not unstaged file edits.
- Upstream
- The remote branch your local branch tracks by default.
- Rejected push
- Git stops when the remote has work you have not integrated.
The Real Command
Terminal
git push -u origin feature/loginExample Output
To https://gitlab.com/acme/shop.git
* [new branch] feature/login -> feature/login
branch 'feature/login' set up to track 'origin/feature/login'.This publishes feature/login to origin. -u remembers that remote branch as its upstream.
Command Details
git pushUse the remembered upstream. This works after the branch has an upstream relationship.
Example Output
To https://gitlab.com/acme/shop.git
d4e5f6a..f7a8b9c feature/login -> feature/logingit push --force-with-leaseA guarded history rewrite. Git refuses if the remote tip no longer matches what it expects. It is safer than --force, but shared history still requires coordination.
Example Output
To https://gitlab.com/acme/shop.git
! [rejected] feature/login -> feature/login (stale info)
error: failed to push some refsgit push --dry-run--dry-run previews the update. Git reports what it would send without changing the remote branch.
Knowledge Check
Share Local Commits
Publish a branch and connect it to its remote-tracking partner.
Question 1 of 5
- Question 1: current
- Question 2: not started
- Question 3: not started
- Question 4: not started
- Question 5: not started