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 repository | Remote repository | |
|---|---|---|
| Where? | Your computer | A server (GitHub…) |
| What for? | Work, commit | Share, back up, collaborate |
| Access | You alone | The 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).
To connect your local repository to a remote repository, you add a reference conventionally called origin.
# Add the remote repository named "origin"
git remote add origin https://github.com/utilisateur/mon-projet.git
# Check the configured remotes
git remote -v| Command | Effect |
|---|---|
git remote add origin <url> | Links local to remote (alias origin) |
git remote -v | Lists remotes and their URLs |
git remote remove origin | Removes the link |
originis only a conventional name for “the main remote repository”. You could call it something else, but everyone usesorigin— 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.
git remote add origin https://github.com/moi/projet.gitTo push is to send your local commits to the remote repository.
# 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| Command | When to use it |
|---|---|
git push -u origin main | First push of a branch (sets up tracking) |
git push | Every later push |
The
-uoption (or--set-upstream) is used only once per branch: it links your local branch to its remote twin. After that,git pushandgit pullknow what to do on their own.
🔧 Mini-exercise — Write the command for the first push of the main branch to origin, establishing tracking.
git push -u origin mainWhen a colleague pushes code, you must fetch their changes to stay up to date.
# Fetch AND merge the remote changes
git pull
# Fetch WITHOUT merging (to inspect first)
git fetch| Command | Effect |
|---|---|
git fetch | Downloads remote novelties, without modifying your work |
git merge | Merges what was fetched into your branch |
git pull | fetch + merge in a single command |
Good habit: run
git pullbefore 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?
git fetchTo clone is to create a complete local copy of an existing remote repository — typically to join a project.
# 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-dossiergit clone does everything at once:
origin toward the cloned URL.git init + remote add | git clone |
|---|---|
| To publish a project that already exists locally | To retrieve a project that already exists remotely |
Summary: you clone when the project already exists online; you do
init+remote add+pushwhen 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.
git clone https://github.com/moi/projet.git mon-dossierHere is the complete daily cycle of collaborative work with a remote repository.
| Step | Command | Goal |
|---|---|---|
| 1 | git pull | Start from the latest version |
| 2 | git add + git commit | Record your work locally |
| 3 | git pull | Fetch what changed in the meantime |
| 4 | git push | Publish 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).
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
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
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
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
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
Answer: b) — git clone copies an existing remote repository locally and configures origin automatically.
Publish the local repository created in lesson 04 on GitHub, then simulate a collaboration by cloning it elsewhere.
# --- 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 pullExpected 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.
git remote add origin <url> links local to remote.git push sends; git pull (= fetch + merge) receives.git clone retrieves an existing repository and configures origin automatically.pull → work → commit → pull → push.Module 02 — Advanced Git and GitHub: Pull Requests, code review, team conflict management, and professional workflows.
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