Remote Repository

7 min

Table of contents


1 — Local repository vs remote repository

Until now, all your work lived on your machine (local repository). A remote repository is a copy hosted on a server (GitHub, GitLab, Bitbucket…), accessible to the whole team.

Local repositoryRemote repository
Where?Your computerA server (GitHub…)
What for?Work, commitShare, back up, collaborate
AccessYou aloneThe whole team

The remote repository plays three roles: backup (your code survives a disk failure), sharing (the team accesses the same code), and meeting point (foundation of collaboration and CI/CD).

↑ Back to top


2 — Link a remote repository

To connect your local repository to a remote repository, you add a reference conventionally called origin.

bash
# Add the remote repository named "origin"
git remote add origin https://github.com/utilisateur/mon-projet.git

# Check the configured remotes
git remote -v
CommandEffect
git remote add origin <url>Links local to remote (alias origin)
git remote -vLists remotes and their URLs
git remote remove originRemoves the link

origin is only a conventional name for “the main remote repository”. You could call it something else, but everyone uses origin — keep that convention.

🔧 Mini-exercise — Write the command that links your local repository to the remote https://github.com/moi/projet.git under the alias origin.

✅ See a solution
bash
git remote add origin https://github.com/moi/projet.git

↑ Back to top


3 — Push changes

To push is to send your local commits to the remote repository.

bash
# First push: link the local branch to the remote branch with -u
git push -u origin main

# Later, a simple push is enough
git push
CommandWhen to use it
git push -u origin mainFirst push of a branch (sets up tracking)
git pushEvery later push

The -u option (or --set-upstream) is used only once per branch: it links your local branch to its remote twin. After that, git push and git pull know what to do on their own.

🔧 Mini-exercise — Write the command for the first push of the main branch to origin, establishing tracking.

✅ See a solution
bash
git push -u origin main

↑ Back to top


4 — Fetch changes

When a colleague pushes code, you must fetch their changes to stay up to date.

bash
# Fetch AND merge the remote changes
git pull

# Fetch WITHOUT merging (to inspect first)
git fetch
CommandEffect
git fetchDownloads remote novelties, without modifying your work
git mergeMerges what was fetched into your branch
git pullfetch + merge in a single command

Good habit: run git pull before you start working and before you push. That avoids most conflicts, because you always start from the latest version.

🔧 Mini-exercise — Which command fetches remote commits without merging them into your branch, so you can inspect them first?

✅ See a solution
bash
git fetch

↑ Back to top


5 — Clone a repository

To clone is to create a complete local copy of an existing remote repository — typically to join a project.

bash
# Clone a repository (creates a folder + downloads the full history)
git clone https://github.com/utilisateur/mon-projet.git

# Clone into a folder with a specific name
git clone https://github.com/utilisateur/mon-projet.git mon-dossier

git clone does everything at once:

  1. Downloads the entire repository (files + history).
  2. Creates a local folder.
  3. Automatically configures origin toward the cloned URL.
git init + remote addgit clone
To publish a project that already exists locallyTo retrieve a project that already exists remotely

Summary: you clone when the project already exists online; you do init + remote add + push when you start from a local project to publish.

🔧 Mini-exercise — Write the command that clones the repository https://github.com/moi/projet.git into a local folder named mon-dossier.

✅ See a solution
bash
git clone https://github.com/moi/projet.git mon-dossier

↑ Back to top


6 — The complete collaborative flow

Here is the complete daily cycle of collaborative work with a remote repository.

StepCommandGoal
1git pullStart from the latest version
2git add + git commitRecord your work locally
3git pullFetch what changed in the meantime
4git pushPublish your commits

This pull → work → commit → pull → push flow is the basic routine. In a company, you add Pull Requests and code review — that is the subject of module 02 (Advanced Git & GitHub).

↑ Back to top


7 — Quiz — Remote repository

Question 1: What is a remote repository?

a) A local branch

b) A copy of the repository hosted on a server, accessible by the team

c) A .gitignore file

d) A particular commit

See the solution

Answer: b) — The remote repository (on GitHub, for example) serves as backup, sharing point, and foundation for collaboration.


Question 2: What does origin usually designate?

a) The first commit of the project

b) The conventional name of the main remote repository

c) The default branch

d) A type of conflict

See the solution

Answer: b)origin is the conventional alias for the main remote repository linked to the local repository.


Question 3: Which command sends your local commits to the remote?

a) git pull

b) git push

c) git clone

d) git fetch

See the solution

Answer: b)git push sends local commits to the remote repository. git pull/fetch do the opposite.


Question 4: What is the difference between git fetch and git pull?

a) None, they are synonyms

b) fetch downloads without merging; pull downloads and merges

c) pull deletes the history

d) fetch sends the commits

See the solution

Answer: b)git pull = git fetch + git merge. fetch alone lets you inspect before merging.


Question 5: When do you use git clone?

a) To publish an empty local project

b) To retrieve a complete copy of a repository that already exists remotely

c) To create a branch

d) To resolve a conflict

See the solution

Answer: b)git clone copies an existing remote repository locally and configures origin automatically.

↑ Back to top


8 — Practice — Publish your repository on GitHub

Instructions

Publish the local repository created in lesson 04 on GitHub, then simulate a collaboration by cloning it elsewhere.


Correction — Expected command sequence

bash
# --- On the existing local project side ---

# 1. Create an EMPTY repository on github.com (via the web interface)
#    → you get a URL: https://github.com/vous/mon-premier-depot.git

# 2. Link local to remote
git remote add origin https://github.com/vous/mon-premier-depot.git
git remote -v

# 3. Push for the first time
git push -u origin main

# --- Simulate a colleague joining the project ---

# 4. Clone elsewhere (another folder)
cd ..
git clone https://github.com/vous/mon-premier-depot.git copie-collegue
cd copie-collegue

# 5. Modify, commit, push
echo "Contribution du collègue" >> README.md
git add README.md
git commit -m "Add a contribution"
git push

# --- Back to the original project ---

# 6. Fetch the contribution
cd ../mon-premier-depot
git pull

Expected result: after the final git pull, the README.md of the original project contains the line added by the “colleague”. The push / clone / push / pull cycle is complete.

You just completed a full Git collaboration by yourself. That is exactly what happens in a team, except that the two copies live on different machines.

↑ Back to top


9 — Summary

Key takeaways

  1. Remote repository = copy on a server (GitHub): backup + sharing + collaboration.
  2. git remote add origin <url> links local to remote.
  3. git push sends; git pull (= fetch + merge) receives.
  4. git clone retrieves an existing repository and configures origin automatically.
  5. Daily routine: pull → work → commit → pull → push.

What's next

Module 02 — Advanced Git and GitHub: Pull Requests, code review, team conflict management, and professional workflows.

↑ Back to top


All rights reserved. Any reproduction, distribution, use or adaptation of this course, in whole or in part, is strictly prohibited without the prior written authorization of Dr. Haythem REHOUMA.

Course created by Dr. Haythem REHOUMA — Development and Deployment of Data Solutions