Remotes
Remotes
Section titled “Remotes”🤔 What is a Remote?
Section titled “🤔 What is a Remote?”A remote is a link from your local repository to a copy hosted on GitHub (or another server). Think of it like a cloud backup for your code.
- Local = your computer
- Remote = GitHub (or GitLab, Bitbucket, etc.)
flowchart LR subgraph Local[Your Computer] REPO[Local Repository<br/>.git] WD[Working Directory<br/>Your files] end
subgraph RemoteServer[GitHub] REMOTE[Remote Repository<br/>origin/main] end
REMOTE -- "git pull<br/>Download changes" --> REPO REPO -- "git push<br/>Upload changes" --> REMOTE REMOTE -- "git clone<br/>Copy entire repo" --> REPO REMOTE -- "git fetch<br/>Check for changes" --> REPO
style Local fill:#3b82f6,color:#fff style RemoteServer fill:#10b981,color:#fff📥 Clone — Copy a Remote Repo
Section titled “📥 Clone — Copy a Remote Repo”git clone https://github.com/username/project.git# Cloning into 'project'...# remote: Enumerating objects: 42, done.# Receiving objects: 100% (42/42), done.
cd projectgit remote -v# origin https://github.com/username/project.git (fetch)# origin https://github.com/username/project.git (push)origin is the default name for the remote repository. Think of it as a nickname for the GitHub URL.
📤 Push — Upload Your Changes
Section titled “📤 Push — Upload Your Changes”# Push main branch to origin remotegit push origin main
# Push a new branch (creates it on GitHub too)git push origin feature-login
# Set upstream (so next time just 'git push')git push -u origin feature-login# Now: git push ← works without arguments📥 Pull — Download & Merge
Section titled “📥 Pull — Download & Merge”git pull origin main# = git fetch + git mergegit pull is two commands in one:
git fetch— download the latest changes from GitHubgit merge— merge them into your current branch
# Better to use fetch + status first:git fetch # check what's new (safe)git status # see if you're ahead/behindgit pull # then pull if needed👁️ Fetch — Check for Changes (Safe)
Section titled “👁️ Fetch — Check for Changes (Safe)”git fetch# remote: Enumerating objects: 5, done.# From https://github.com/username/project# a1b2c3d..f6e5d4c main -> origin/mainfetch downloads new data but does not change your working files. It’s a safe way to check what’s new.
After fetching, you can compare:
git log origin/main..main # commits you have that origin doesn'tgit log main..origin/main # commits origin has that you don't🗺️ Common Remote Commands
Section titled “🗺️ Common Remote Commands”# List remotesgit remote -v
# Add a new remotegit remote add origin https://github.com/user/repo.git
# Remove a remotegit remote remove origin
# Rename a remotegit remote rename origin upstream
# Show info about a remotegit remote show originIn Simple Words
Section titled “In Simple Words”- A remote links your local repo to GitHub —
originis the default nickname git clonedownloads a repo from GitHub to your computergit pushuploads your commits to GitHubgit pulldownloads and merges changes (=fetch+merge)git fetchis safe — it checks for new changes without modifying your files- Always pull before you push to avoid conflicts!