Distributed architecture

Your PC does not rely on the cloud: the entire repository lives on disk

Unlike obsolete centralized systems (like SVN), Git is peer-to-peer. Your local clone holds the complete graph of commits, tags, and branches. Platforms like GitHub are simply remote repositories with a conventional alias: origin.

See which operations are 100% local without network and which require internet.
💻 Local Repository 🟢 Connected to Internet
  • ✓ git commit (instant, zero network latency)
  • ✓ git branch & git switch (sub-millisecond branch operations)
  • ✓ git log & git diff (full offline history queries)
  • ✓ git merge & git rebase (autonomous local integration)
☁️ Remote (GitHub - origin) https://github.com/org/repo.git

Stores the authoritative canonical copy for the team. Synchronized strictly over network protocols (SSH or HTTPS).

git push (subir) git fetch (descargar) git pull (descargar + unir)
Code publishing

git push: transferring your confirmed commits to the cloud

Running git commit saves changes on your computer. To share them with your team or back them up to GitHub, you run git push. This sends object packs and advances origin/main on the server.

💻 Local: main In sync
C1
C2
git push →
☁️ origin: refs/heads/main In sync
C1
C2
$ Both repositories are at commit C2. Click "Make local commit" to advance.
Safe download

The key difference: git fetch vs git pull

Many developers confuse these commands: git fetch is safe and non-intrusive (downloads objects and updates origin/main without touching your working tree). git pull is aggressive: it fetches and immediately merges into your current branch.

origin (GitHub)

Commit C4 pushed by your teammate in cloud.

1. git fetch Only updates local tracking pointer
→
2. git merge origin/main Merges into your Working Tree
↓↓
Local PC

origin/main (ref): Points to C2

Working Tree (archivos): Points to C2 (Clean)

💡 Use git fetch when you want to review changes before blindly merging them.

Tracking branches

Why we use git push -u origin main and what upstream does

The first time you push a branch, Git does not know which remote branch to link it to. The -u (--set-upstream) flag creates a permanent link in your local config. From then on, simply typing git push or git pull suffices.

See how terminal output changes whether -u was configured or not.
Internal configuration (.git/config)
[core]
	repositoryformatversion = 0
[remote "origin"]
	url = git@github.com:facundo/proyecto.git
	fetch = +refs/heads/*:refs/remotes/origin/*
[branch "main"]
	remote = origin
	merge = refs/heads/main
Bare command: $ git push

Everything up-to-date
Branch 'main' set up to track remote branch 'main' from 'origin'.

Divergence and conflicts

Error: [rejected - non-fast-forward] and how to recover

If a teammate pushed changes to GitHub while you worked locally, your histories diverge. Git blocks your push to protect their code. The mandatory remedy is to pull, integrate, and push again.

origin: C1 → C2 → C3 (remoto)
local: C1 → C2 → C4 (local)
! [rejected] main -> main (non-fast-forward) error: failed to push some refs to 'github.com:org/repo.git' hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first integrate the remote changes hint: (e.g., 'git pull ...') before pushing again.
Professional protocol

The 5-step daily synchronization ritual

Following this technical routine at the start and end of every development day prevents 95% of conflicts and divergence in software teams.

01

Pull changes before touching code

Start your day updating main with changes your team merged overnight.

git switch main
git pull
02

Branch out with purpose

Never code directly on main. Isolate your work in a well-named feature branch.

git switch -c feat/user-auth
03

Small and frequent commits

Do not pile 5 days of work in one giant commit. Make atomic, testable commits.

git add -p
git commit -m "feat(auth): validate token"
04

Push with upstream tracking

Publish your branch to the remote repository configuring tracking with -u.

git push -u origin feat/user-auth
05

Open Pull Request for peer review

On GitHub, open the PR against main, describe context, link the issue, and await CI/CD.