Skip to main content

Remote Repositories

Up to this point, all the commands we have seen act strictly locally on your computer's hard drive. But the true magic of Git happens when you collaborate with others and back up your code in the cloud (the "Internet").

Services like GitHub, GitLab, or Bitbucket do not own Git; they are companies that rent space on their servers for you to host copies (remote repositories) of your local project and offer web interfaces to manage them.

Understanding origin

When you clone a repository from GitHub to your computer using git clone, Git automatically creates an invisible connection between the local folder on your computer and the internet URL from which you downloaded it.

By convention, the name of that connection (or "remote URL") is nicknamed origin.

You can see your remote connections by typing:

git remote -v

What happens if you started your project from scratch with git init and now you want to upload it to GitHub?

  1. Go to GitHub.com and create a new and empty repository.
  2. Copy the URL it provides you.
  3. Tell your local Git to add that URL under the name origin:
git remote add origin https://github.com/your-username/repo-name.git

☁️ Uploading changes to the cloud: git push

You have made several commits on your computer (offline) and now you want to upload them to GitHub so your team can see them, or simply as a backup copy.

The command is "push". You must tell Git which server you want to send them to (origin) and exactly which branch you are pushing (e.g., main or feature-login).

Example - Upload the main branch:

git push origin main

Example - Upload a new development branch for the first time:

# The '-u' flag links your local branch with the new remote branch for the future
git push -u origin feature-dark-mode

📥 Downloading changes from the cloud: git pull

Imagine your teammate uploaded their changes to GitHub last night while you were sleeping. If you open your computer in the morning, your local code will not magically update itself.

You must "pull" the changes from GitHub to your hard drive:

git pull origin main

This command does two things silently underneath:

  1. Contacts origin and downloads everything new.
  2. Tries to make an automatic merge of the new files with the local files you already had open in your terminal.

Important: It is an excellent practice to run git pull every morning before starting to code to ensure you have the very latest version from the entire team on your computer and avoid future conflicts.