Version control becomes powerful when you collaborate. Git remotes are references to repositories hosted on other machines — typically GitHub, GitLab, or a self-hosted server. This lesson covers how to link your local repository to a remote and keep them in sync.
What is a Remote?
A remote is a named URL pointing to another Git repository. By convention, the remote you cloned from is named origin. You can have multiple remotes — for example, origin for your fork and upstream for the original repository you forked from.
# List all remotes and their URLs
git remote -v
# Add a new remote
git remote add upstream git@github.com:original-owner/repo.git
# Change a remote URL (e.g., switching from HTTPS to SSH)
git remote set-url origin git@github.com:yourusername/repo.git
# Remove a remote
git remote remove upstream
git clone
git clone git@github.com:username/repository.git
# Clone into a specific directory name
git clone git@github.com:username/repository.git my-local-name
# Shallow clone — only the latest commit, no history (faster for CI)
git clone --depth=1 git@github.com:username/repository.git
Cloning automatically sets up origin pointing to the cloned URL and creates tracking branches for all remote branches.
git fetch
# Download all new commits from origin without changing local branches
git fetch origin
# Fetch from all remotes
git fetch --all
git fetch is safe — it downloads objects and updates remote-tracking branches (like origin/main) but never touches your local branches. Use it to see what your teammates have been doing before deciding whether to merge.
git pull
# Fetch and merge origin/main into current branch
git pull
# Fetch and rebase instead of merge (cleaner history)
git pull --rebase
git pull = git fetch + git merge. If there are diverged commits, this creates a merge commit. Many teams prefer git pull --rebase to keep a linear history. You can make rebase the default:
git config --global pull.rebase true
Remote-Tracking Branches
When you fetch, Git updates remote-tracking branches — read-only references that represent the state of remote branches at the time you last fetched. They look like origin/main, origin/feature/auth. You never commit directly to these; they are updated only by fetch/pull.
# See all local and remote-tracking branches
git branch -a
git push
# Push current branch to its upstream remote branch
git push
# Push a specific branch and set its upstream tracking in one step
git push -u origin feature/user-auth
# Push all local branches
git push --all
# Delete a remote branch
git push origin --delete feature/old-branch
The -u (set upstream) flag links your local branch to the remote branch. After running it once, you can use git push and git pull without specifying the remote and branch name.
Typical Collaboration Workflow
git switch main— start from maingit pull— get the latest changes from the teamgit switch -c feature/my-feature— create a feature branch- Make changes,
git add,git commit git push -u origin feature/my-feature— publish the branch- Open a Pull Request on GitHub
- After approval, merge the PR — the remote branch can then be deleted