CodeRigor

FREE LESSON

Remotes, tracking, fetch & safe publication

Separate local and remote-tracking refs, publish a topic branch, and reason about rejected updates.

A remote is a configured repository destination, usually associated with a name such as origin. That name is conventional, not privileged. Git can communicate over several transports; these labs use only another directory containing a bare repository. A bare repository stores history and references without a normal checked-out working tree. It lets you practice publishing and collaboration entirely offline.

Three references, not one
start / 3
Three independent references. Fetch updates the local observation; it does not merge into main.
Three references, not one
Three independent references. Fetch updates the local observation; it does not merge into main.

Keep the three references separate

Your local main, your local remote-tracking reference origin/main, and main in the remote repository are distinct references. git fetch origin obtains objects and updates remote-tracking information according to the configured refspec. It does not automatically merge into your current branch. origin/main reflects your last relevant observation, not a live subscription to the server. Inspect git remote -v and git branch -vv when a command's destination or tracking relationship is unclear.

git pull combines fetching with an integration choice. With --ff-only, integration succeeds only when your branch can fast-forward; divergence causes a refusal rather than silently selecting merge or rebase. A refusal is information to inspect, not a reason to force an unrelated operation. Decide whether to merge, rebase an unpublished topic, or coordinate another approach.

Fetch and integrate are separate
start / 4
Fetch and integrate are separate

Publish the branch you mean

git push -u origin feature/report asks origin to update the same-named branch and records an upstream for your local branch after a successful update. An explicit refspec has the form source:destination. HEAD:main targets remote main regardless of your topic branch's name. Review that destination before publishing; a successfully executed command can still change the wrong reference.

Git commands
git remote -v
git branch -vv
git push -u origin feature/report
git branch -vv
Explicit publication
start / 4
Explicit publication

Understand a rejected update

A normal push protects branch history by refusing a non-fast-forward update. Fetch and inspect the graph to understand the missing work. For an intentionally rewritten, coordinated branch, force-with-lease can check an expected remote reference value before replacing it; an explicit expected value is more precise than assuming your remote-tracking ref has not changed in the background. A lease is a reference-value check, not permission to overwrite teammates' work. The course lab needs no forced update.

Hosting-service pull requests add a review workflow around Git branches; they are not Git objects and do not replace the local graph model. Credentials, network reachability, protected-branch rules and review requirements are additional deployment concerns. In this lab, focus on the observable contract: a published topic branch, the correct upstream, and unchanged main branches even when the remote has a newer main.

Watch & read

Free lectures, talks and readings that cover this skill from another angle. All resources →

Review the object/reference model and core workflows here. The authored lesson and linked Git manual cover the current command forms and advanced details used in this lab.