Back to roadmap

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/login
Example 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 push

Use 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/login
git push --force-with-lease

A 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 refs
git 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

  1. Question 1: current
  2. Question 2: not started
  3. Question 3: not started
  4. Question 4: not started
  5. Question 5: not started
Command Challenge

Publish feature/login to origin and remember that remote branch as its upstream.