Elena' s AI Blog

Git Remotes

24 Jun 2024 (updated: 07 Sep 2026) / 9 minutes to read

Elena Daehnhardt

Midjourney AI-generated art, June 2024: teamwork with many computers, Bob and Alice work together, HD, Canon lens


TL;DR:
  • Use 'git remote add origin URL' to connect repos, 'git fetch' to update, 'git push' to share changes. Remotes enable backup, collaboration, and version control—essential for team workflows.

Previous: Part 22 — The Token Way to GitHub Security

Next: Part 24 — Git Checkout for overwriting directories from different branches

Overview: Managing Git Remote Repositories

This post is about managing remote repositories in Git. We explore tasks such as adding, renaming, removing remotes, and updating remote URLs. We also practice fetching, pulling, and pushing changes to and from remote repositories.

What Are Git Remotes? Definition and Purpose

A Git remote is a named reference to a version of your repository hosted on another computer or platform such as GitHub or Bitbucket. Git remotes connect your local project to those copies, letting you back up, share, and synchronise your code across machines.

Are Git Remotes similar to Git branches? Remotes are not branches, but they work together. Branches are like alternate timelines within your repository, while remotes are links to entirely different repositories (potentially with their own sets of branches). You can have branches on your local and remote repositories, and Git helps keep them in sync.

Using Git Remotes: Best Practices

You can use Git remotes while working in a team or alone. It is a good idea to follow best practices, such as:

  1. Use clear names like “origin” (main) or “upstream” (original project).
  2. Fetch Often to stay updated and avoid conflicts.
  3. Push with caution and double-check before sharing changes.

Git Remotes for Solo Coding: Backup and Version Control

Imagine Bob, a solo coder working on his passion project. He uses Git to track changes but wants an extra layer of security and organization. That’s where remotes come in.

Bob creates a remote repository on GitHub, calling it “origin.” Now, he has two versions of his project:

  1. Local Repository: On his computer, he actively codes and experiments.
  2. Remote Repository (“origin”): On GitHub, serving as a secure backup and a way to track his project’s history.

The remotes are essential for these:

  1. Backup: If Bob’s computer crashes, his code is safe and sound on GitHub. He can easily clone the “origin” repository to a new machine and pick up where he left off.
  2. Version Control: Bob can push different versions of his project to the remote, creating snapshots in time. If he ever needs to revert to an older version, it’s on GitHub.
  3. Organization: Remotes help Bob keep his project organized and separate from other projects he might be working on.
  4. Sharing (Optional): If Bob decides to share his project with others later, he can easily grant them access to the “origin” repository.

Git Remotes for Team Collaboration

Now, imagine Alice joining Bob’s project. Remotes make their collaboration seamless:

  1. Alice Clones: Alice uses git clone to get a copy of the project from the “origin” repository.
  2. Stay in Sync: Bob and Alice use git push and git pull to share their changes and keep their local copies up-to-date.
  3. Work on Different Features: They create separate branches and push them to the remote to work independently.
  4. Merge Their Work: They merge their branches on the remote to combine their contributions.

Should you be interested in teamwork with Git, read my post Collaboration in GitHub.

Git Remote Commands Reference

🔒 Subscribe to keep reading.

Using Personal Access Tokens for Git Authentication

🔒 Subscribe to keep reading.

Conclusion

🔒 Subscribe to keep reading.

References

🔒 Subscribe to keep reading.

You've hit a Deep Dive tutorial.

I spend dozens of hours researching, coding, and breaking things to write these guides. This content is free, but reserved for my subscriber community. Drop your email below to unlock this guide (and all past/future deep dives):

Already a subscriber? Use the magic link from your last newsletter, or reset your password.

New subscribers get an inbox mail: Set a password to unlock articles. The form does not log you in — use the same email afterwards.

desktop bg dark

About Elena

Elena, a PhD in Computer Science, simplifies AI concepts and helps you use machine learning.





Citation
Elena Daehnhardt. (2024) 'Git Remotes', daehnhardt.com, 24 June 2024. Available at: https://daehnhardt.com/blog/2024/06/24/git-remotes/
All Posts