Remotes and GitHub


Every repository in this handbook so far has lived in one place: your own machine. That works fine right up until you want a backup that survives a dead laptop, want to pick up the project from a second computer, or want anyone else to touch the code. What you need is a copy of the repository sitting somewhere every machine involved can reach. That copy is called a remote, and GitHub is where most developers put it.
What a remote is (and where GitHub fits in)
A remote is a copy of your repository hosted somewhere other than your own machine, most often on GitHub. When you clone a repository, Git already sets one up for you, named origin by default. Run git remote -v (the -v asks for the URLs as well as the names) to see it:
$ git remote -v
origin https://github.com/mara-chen/weather-app.git (fetch)
origin https://github.com/mara-chen/weather-app.git (push)Every remote Git knows about is listed twice, once for fetching and once for pushing, because in theory the two could point at different addresses. In practice they're almost always the same one. origin is the nickname Git assigns automatically on clone. You can rename it or add a second remote pointing somewhere else, but nearly every project you touch will call its main remote origin.
This is a good moment to restate the distinction that trips up nearly everyone starting out: Git and GitHub are not the same thing. Git is the version-control tool running on your machine, recording commits whether or not you're connected to anything. GitHub is a website that hosts a copy of your repository and gives you a remote to push to and pull from. git remote, git push, and git pull are the commands that connect the two: they're how the Git running on your laptop talks to a repository sitting on GitHub's servers.
origin. Run git remote -v any time to see which remotes your repository knows about. Git and GitHub are not the same thing: Git is the tool on your machine, GitHub is where your remote often lives. Getting that split straight early saves a lot of confusion later. Where to host your remote: GitHub and the alternatives
Everything a remote does is plain Git, and that has a consequence worth knowing early: the host on the other end is swappable. To Git, every host is a URL in your config, and git push, git pull, and git fetch behave identically against all of them. What a host adds sits one layer up: a web view of your code, a review flow, issue tracking, and access control. Here is the landscape, with the trade-offs stated plainly:
- GitHub is the biggest by far and hosts the large majority of open-source work. Its strength is the network: the projects you want to contribute to are already there, tutorials assume it, and employers look for your profile on it. The trade-off is that it is a closed platform (owned by Microsoft), and the more you lean on its extras beyond Git hosting, the more tied to it you become.
- GitLab is the closest full alternative, with the same core features under slightly different names (pull requests are "merge requests" there). Its standout is a self-managed edition you can run on your own servers, which is why companies that keep code in-house often pick it. The trade-off is that it bundles a lot, and the platform can feel heavier than the code hosting you came for.
- Bitbucket is the host from Atlassian, built to sit next to its project-tracking and documentation tools, Jira and Confluence. If your team already lives in those tools, it slots straight in. Outside that ecosystem it has the smallest community of the big three and little open-source presence.
- Codeberg is a nonprofit host for open-source projects, run on the open-source platform Forgejo. The draw is that no company owns your host and the platform itself is open source. The trade-off is scale: fewer integrations, a smaller community, and a focus on open source rather than private team work.
- Self-hosting underlies all of these: run Forgejo or Gitea, both free and open source, or GitLab's self-managed edition on hardware you control. You get full control and privacy; the trade-off is that keeping it running becomes your job.
This handbook uses GitHub in its examples because it hosts most open-source work and is where you are most likely to collaborate first. Every command in this chapter transfers unchanged to any other host: swap the URL and the daily loop stays the same. The differences live one layer up, in each site's web interface for reviewing and merging work, which is where the next chapter's pull request flow comes in.
Sending and getting your work: git push and git pull
With a remote in place, two commands cover most of the daily work. git push sends your local commits up to the remote. git pull brings down commits made elsewhere and merges them into the branch you're on.
$ git push origin main
Enumerating objects: 5, done.
Writing objects: 100% (3/3), 312 bytes | 312.00 KiB/s, done.
To https://github.com/mara-chen/weather-app.git
9f8e7d6..a1b2c3d main -> mainorigin is the remote, main is the branch you're sending. That last line is the part worth reading: it shows main on the remote moving from one commit to the next.
Pulling works the same way, in reverse:
$ git pull origin main
remote: Enumerating objects: 4, done.
Unpacking objects: 100% (4/4), done.
Updating a1b2c3d..b7c9e21
Fast-forward
src/index.js | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)That's the whole loop for working alongside other people on one project: pull down whatever changed before you start, do your own work and commit it, push it back up. Pull before you push whenever you share a branch with anyone else. Skip the pull and your push can land on top of commits you never saw, which Git will refuse rather than risk losing someone's work.
git push sends your commits up to the remote, and git pull brings down commits made elsewhere and merges them into your branch. Pull before you start working and push when you are done, and you stay in sync with anyone else touching the project. Skipping the pull is the most common reason a push gets rejected. git fetch vs git pull
git pull does two things in one step: it downloads whatever changed on the remote, then immediately merges those changes into the branch you're on. git fetch does only the first half. It downloads new commits but never merges them into your branch. Your current branch, and your working files, stay exactly where they were until you tell Git to merge or pull.
This is the trip-up almost everyone hits at least once: run git fetch, see no visible change anywhere, and assume nothing happened on the remote. Something did happen: fetch has not touched your working branch yet. To see what came down, look at the remote-tracking branch from earlier in this chapter: git log origin/main shows commits sitting on the remote that haven't reached your local main. When you're ready to bring them in, git merge origin/main does it, or git pull runs fetch and that merge for you in one command.
git pull downloads new commits and merges them into your branch in one step. git fetch only downloads them and updates Git's memory of where the remote stands; your branch stays put until you merge. Seeing no change in your files right after a fetch is expected, the new commits are waiting on the remote-tracking branch. Where this leaves you
Push, pull, and fetch get your commits onto a shared remote and back again, which covers most of what day-to-day collaboration in Git requires. Everything here builds on the commit loop: you still stage and commit locally first, a remote only changes where those commits can travel. The next piece is doing that collaboration through GitHub itself, proposing a change and having it reviewed before it merges. The pull request flow picks up exactly there. If a term in this chapter still feels shaky, remote-tracking branch, refspec, upstream, the Glossary has a plain definition for each, and What is Git is worth a second look for the Git-versus-GitHub distinction on its own.

