Git Remote: Add Origin, Fetch, and Merge Remote Branches
Table of Contents
Git is distributed, which means your repo and my repo can both be valid “sources of truth”. In practice, teams usually pick one remote as the shared source (often GitHub) and sync local work against it… but that’s just a convention. Let’s dig into how syncing Git repositories to GitHub works, and how that’s just one way to work with Git.
All the content from our Boot.dev courses are available for free here on the blog. This one is the “Remote” chapter of Learn Git. If you want to try the far more immersive version of the course, do check it out!
What Is a Git Remote?
A “remote” is just another Git repository connected to your local one.
There is no magical central repo built into Git itself. GitHub (the website) is not special to Git (the tool), it’s just a common place where teams host a shared repo. Other popular Git hosting services include GitLab and Bitbucket.
That shared repo is usually named origin… again just by convention.
How Do You Add origin to a Local Repository?
Use git remote add:
git remote add origin https://github.com/username/repo.git
Syntax:
git remote add <name> <uri>
For local practice repos, a relative path works great. For hosted remotes, that URI is almost always over HTTPS or SSH. For example, you can actually create a local “remote” by pointing to another local repo:
git remote add localorigin ../some-other-repo
Does Adding a Remote Download Everything?
Nope.
Adding a remote only stores the connection info. It does not download the remote’s object database into your local .git/objects yet.
That’s why a fresh repo can have a configured origin and still show no commits in local git log.
What Does git fetch Actually Do?
The git fetch command downloads commits, trees, blobs, and ref updates from the remote into your local Git database.
git fetch
The
fetchcommand updates remote-tracking refs, but doesn’t merge anything into your current branch.
That’s why it’s safe to run often. You get new information without touching your working files.
If you’re trying to combine histories directly, that’s when Git Merge or Git Rebase comes in.
Why Does git log Show Nothing After Fetch Sometimes?
Because git log (without arguments) shows the history of your current local branch.
After fetch, you might have remote-tracking branches like origin/main, but your local main may still be empty or behind.
To inspect remote history directly:
git log --oneline origin/main
Or a feature branch:
git log --oneline origin/update_dune
How Do You Merge a Remote Branch Into Local main?
Once you’ve fetched:
git switch main
git merge origin/main
If your local main has no extra commits, this is often a fast-forward merge.
That means Git just moves your local branch pointer forward, no extra merge commit needed.
After that, plain git log on local main should match the history you saw in origin/main.
What’s a Good Basic Remote Workflow?
For day-to-day work, you can use fetch like this:
git fetch originto get the latest commits and refs from the remote- update your local branch with rebase (or merge I guess) to incorporate those changes
But honestly, it’s much easier to just pull:
git pull origin main
This combines fetch and merge (or even better, rebase) into one step.
That pattern keeps your local state predictable and avoids… ahem… surprise conflicts. Basically what I’m saying is pull often!
Frequently Asked Questions
What is a Git remote?
A Git remote is another Git repository your local repository can talk to by name, usually for sharing commits with teammates.
What is origin in Git?
origin is the conventional default name for your primary remote repository.
Does git fetch change my files?
No. git fetch downloads new commit and ref data from a remote but does not update your current working files.
How do I view commits on a remote branch?
Run git log origin/branch-name after fetching to inspect the remote-tracking branch history.
How do I merge a remote branch into local main?
Switch to local main, fetch remote updates, then run git merge origin/main.
Related Articles
Git Rebase: Keep History Linear Without Merge Commits
Apr 01, 2026 by ThePrimeagen - Ex-Netflix engineer, NeoVim ricer, and Git rebaser
If git merge feels noisy, that’s because it can be. Lots of noisy merge commits make history harder to scan, especially when you’re just trying to understand what actually changed. git rebase takes a different approach: instead of creating a merge commit, it replays your branch commits on top of the latest base commit so your history stays clean and linear.
Git Reset: Undo Commits With --soft and --hard
Apr 01, 2026 by ThePrimeagen - Ex-Netflix engineer, NeoVim ricer, and Git rebaser
If you’ve ever made a commit and immediately thought “noooope”, then git reset is what you need. It’s one of the most useful Git commands for undoing work, but it’s also one of the easiest to misuse. The --soft version is usually safe and predictable. The --hard version is powerful and can absolutely nuke your local changes.
GitHub + Git: Push, Pull, and Pull Requests
Apr 01, 2026 by ThePrimeagen - Ex-Netflix engineer, NeoVim ricer, and Git rebaser
Git is the open-source command-line version control tool, and GitHub is basically just a collaboration on top of it. You can absolutely use Git without GitHub, but for most teams, GitHub (or something similar) is where a lot of the collaboration happens. Linus Torvalds created Git, and… well we don’t talk about who owns GitHub these days…
Gitignore Patterns: What to Ignore and Why
Apr 01, 2026 by ThePrimeagen - Ex-Netflix engineer, NeoVim ricer, and Git rebaser
Many devs adopt the git add . (yolo, just yeet it all into the commit) workflow. It is fast, simple, and usually correct. But eventually you’ll have files in your repo directory that should never be committed: secrets, generated artifacts, dependency folders, and random local junk. That’s what .gitignore is for.