Stage 6 - Working with Remote Repositories and GitHub

Up to now, task-service could be developed and debugged entirely locally. The next step is making it collaborative: publishing the current local branch so the team can fetch, review, and extend it.

Local and remote Git repositories

Local vs remote is an explicit boundary

Your local repository has the latest state you currently work with. A remote repository is the shared copy, usually on GitHub. They do not synchronize automatically every minute unless you use automation or pull actions in your editor.

So if teammate Anna pushed new work, your machine stays old until you fetch/pull. This is good: you control when to integrate remote updates.

One local repository to remote

Imagine your current project already has local commits. Add GitHub as remote origin and publish main:

git remote add origin https://github.com/your-user/task-service-tutorial.git
git branch -M main
git push -u origin main
``+

`origin` is a convention. `-u` links local main with remote main, so later `git push` / `git pull` know destination automatically.

## Cloning when repo already exists

If a repository already lives in GitHub and a new teammate joins:

```bash
git clone https://github.com/example-org/task-service-tutorial.git
cd task-service-tutorial
git remote -v

git clone configures the remote automatically.

fetch vs pull in project rhythm

git fetch downloads remote changes metadata and refs but does not touch working files yet.

git pull does fetch + integrate into current branch immediately.

In task-service, use fetch when you want to inspect remote commits first, pull when you already agree to sync.

Command What it does Best moment
git remote -v Shows remote target mapping Before first push/pull operations
git fetch Safe: updates local remote-tracking refs Before manual review of incoming commits
git pull Fetch + merge/rebase current branch During routine syncing with team branch
git push Send local commit history to remote Publish ready branch work

Stage 7 will build on this with PRs and review comments, so this step creates the collaboration infrastructure.

Operational check for real teams

Before pushing anything, make sure your branch is based on up-to-date main and your remote is configured as expected. In many incident cases, errors come from pushing to the wrong fork or from stale local main.

A stable remote routine:

  1. git switch main
  2. git pull
  3. git switch <feature>
  4. run change + commit
  5. git push

This routine turns remote collaboration into repeated, predictable actions and is easier to automate than ad-hoc commands.

Keep secrets and credentials out of history

Remote workflows often fail because credentials accidentally enter source files. For task-service, keep tokens outside repo and use environment files or CI secrets.

Git cannot protect bad security habits by itself; it only protects history. Process and policy do.

Glossary
version control
A system for tracking project changes over time so developers can inspect, compare, and restore previous states.
repository
A storage area for a project, its files, history, and related metadata.
commit
A saved Git history point that records a related set of changes, the author, and the reason for the change.
branch
An independent line of work where changes can be developed without immediately affecting another line.
merge
The operation that combines changes from one branch or source into another.
conflict
A situation where a tool cannot automatically combine changes because different edits affect the same part.
staging area
The Git area where selected changes are prepared before they become part of the next commit.
working tree
The current files and folders checked out in your project directory, including uncommitted edits.
diff
A comparison that shows exactly which lines or values were added, removed, or changed.
remote
A named connection to a repository stored somewhere else, usually on a server such as GitHub.
clone
The operation that copies an existing repository from a remote location to your local machine.
push
The operation that sends local commits or changes to a remote repository.
pull
The operation that downloads changes from a remote repository and integrates them locally.
pull request
A review request that proposes merging one branch into another and gives teammates a place to discuss changes.
fork
A personal copy of another repository, usually used to propose changes without direct write access.
review
The engineering practice of checking changes for correctness, clarity, risks, and maintainability.
rollback
A deliberate return to an earlier safe state after a mistake, regression, or unwanted change.
rebase
A Git operation that moves commits to a new base commit, often used to make history more linear.
tag
A named marker pointing to a specific version, commit, image, or release artifact.