Working with Remotes
What is a Remote?
A remote repository is just a copy of your project folder that lives on the internet (like on GitHub). Usually, your local computer calls this remote cloud folder origin (or o/ for short).
# Copy a project from the internet onto your computer for the first time
git clone
Remote-Tracking Branches
Your computer keeps a set of hidden "read-only" branches that remember what the internet version looked like the last time you checked. These have names like o/main (Remote Origin's Main branch).
Warning: If you jump onto o/main, you are looking at a snapshot of the cloud. If you make new saves here, they won't save to your real local branch.
Syncing with the Cloud
1. Git Fetch (Download Only)
Downloads any new saves your teammates uploaded to the cloud, and updates your o/main pointers. It does not touch or change your personal local work.
git fetch
2. Git Pull (Download and Combine)
Because you almost always want to combine your teammates' work with your own after downloading it, git pull does a git fetch AND a git merge at the exact same time.
git pull
Git Push (Uploading Your Work)
When you are happy with your local saves and want to share them with the world, send them to the cloud.
git push
When History Conflicts (Divergent History)
If a teammate uploaded work to the cloud while you were working on your computer, Git will block your push so you don't overwrite their code.
You must download their work and place yours on top of it before you are allowed to push:
# The recommended workflow:
git pull --rebase
git push
Stashing: Pausing Your Work Without Committing
Imagine you are halfway through typing up a messy feature on a branch, and your boss suddenly tells you to jump over to main right now to fix an emergency typo. You can't switch branches because your current code is broken and uncommitted.
You can use git stash to temporarily hide your messy changes in a drawer so your workspace becomes clean.
# Hide your current unsaved work away safely
git stash
# Your workspace is now clean! You can jump branches, fix the emergency bug...
git checkout main
# (do the fix, commit, and then come back to your feature branch)
git checkout feature-branch
# Take your messy work back out of the drawer and put it back on your screen
git stash pop
Advanced Remote Tricks
Fixing a "Push Rejected" Mistake
If you accidentally wrote code directly on your local main branch instead of a side feature branch, and the server rejects your push, use this sequence to fix it safely:
# 1. Force your local main branch back to match what is safely in the cloud
git branch -f main o/main
# 2. Take your new unsaved work and move it to a proper feature branch
git checkout -b feature-branch
# 3. Safely push that new branch to the cloud instead
git push origin feature-branch
Direct Destination Controls
- Choosing Exactly Where to Push You can tell Git exactly where to send your code, regardless of what branch you are currently standing on on your computer.
# Structure: git push <remote-name> <branch-name>
git push origin main
The Destination Colon (:)
If you want to take code from a local branch but save it under a completely different name in the cloud, use a colon:
# Structure: git push origin <your-local-source>:<the-cloud-destination>
# Example: Push your local 'foo' branch into the cloud's 'main' branch
git push origin foo:main
# Example: Push a previous save point into a brand new cloud branch
git push origin main:newBranch
Explicit Fetching
Just like pushing, you can request to download a single specific branch from the cloud without updating anything else:
# Go grab just the 'foo' branch from the cloud
git fetch origin foo