Search Knowledge

© 2026 LIBREUNI PROJECT

Remotes and Collaboration

The Distributed Model

One of Git’s defining characteristics is that it is a Distributed Version Control System (DVCS). Unlike Centralized VCS (like Subversion or CVS) where clients checkout the latest version of files, in Git, every client mirrors the repository fully.

This means that if the server dies, any of the client repositories can be sent up to the server to restore it. Every clone is really a full backup of all the data.

Managing Remotes

To collaborate with others, you use “remotes”. A remote is simply a reference to a version of your project that is hosted on the internet (e.g., GitHub, GitLab) or network.

Viewing Remotes

To see which remotes you have configured:

git remote -v

This will list the shortnames (like origin) and the URLs that Git has stored for reading and writing.

Adding a Remote

If you initialized a repository locally, you need to add a remote explicitly to push your code.

git remote add origin https://github.com/user/repo.git

Here, origin is just the standard default name for your primary remote, but you could name it anything (e.g., upstream, backup, production).

Cloning a Repository

If you are starting a project that already exists remotely, you clone it.

git clone https://github.com/liberuniversity/course-content.git

This command does several things:

  1. It initializes a new .git directory.
  2. It pulls down all the data for that repository.
  3. It checks out a working copy of the latest version of the default branch.
  4. It automatically sets up your local main branch to track the remote origin/main branch.

Synchronizing Changes

Collaboration involves sending your commits to a remote and downloading commits from others.

Fetching vs. Pulling

There is a crucial distinction between fetch and pull that often confuses beginners.

git fetch downloads the data from the remote project that you don’t have yet. It updates your “remote-tracking branches” (like origin/main), but it does not merge changes into your working directory. It is safe and non-destructive.

git fetch origin

git pull is essentially a git fetch followed immediately by a git merge. It downloads the changes and tries to merge them into your current branch.

git pull origin main

Recommendation: If you want to see what others have done before integrating it, use fetch then log (or diff), and finally merge. If you just want to get up to date and resolve conflicts later, use pull.

Code
skinparam rectangle {
  BackgroundColor #FFFFFF
}

rectangle "Remote Repository" as Remote
rectangle "Local .git (Objects)" as LocalGit
rectangle "Working Directory" as WorkDir

Remote -> LocalGit : git fetch
LocalGit -> WorkDir : git merge
Remote -> WorkDir : git pull
Remote RepositoryLocal .git (Objects)Working Directorygit fetchgit mergegit pull

Pushing Changes

When you have commits that you want to share, you must push them upstream.

git push origin main

This command takes your local main branch and pushes it to the origin remote. This only works if you have write access and if no one else has pushed in the meantime. If someone else has pushed, you must pull their changes and merge them before you can push.

Setting Upstream

The first time you push a new branch, you often need to set the “upstream” (or tracking) relationship. This links your local branch to the remote branch so you can use git pull and git push without arguments later.

git push -u origin feature-login

The -u (or --set-upstream) flag establishes this link.

Remote Tracking Branches

Remote-tracking branches are references to the state of remote branches. They are local and you cannot move them; Git moves them for you whenever you do network communication. They act as bookmarks.

They take the form <remote>/<branch>. For example, origin/main.

If you are on your local main branch and you do git fetch origin, Git updates origin/main to reflect the latest commit on the server. Your local main pointer stays where it was.

git
1# Simulate checking remote details
2# Note: In this sandbox, we don't have real network access to GitHub
3# but we can simulate the configuration commands.
4git init
5git remote add origin https://github.com/simulation/test.git
6git remote -v
7git config --get remote.origin.url

Deleting Remote Branches

Once a feature is merged and the branch is deleted on the server, you might still have the reference locally. To clean up your local references:

git fetch --prune

To explicitly delete a branch on the remote server:

git push origin --delete feature-login

Which command downloads changes from the remote but does NOT modify your working directory?

Adding a Remote

# Add a remote named 'upstream' with url 'https://git.example.com/repo.git'
git remote  upstream https://git.example.com/repo.git