A remote connects your local repository to a copy on GitHub. In this lesson you will add and manage remotes, understand origin and upstream, and read remote-tracking branches such as origin/main so push and pull make sense.
📖 What You’ll Learn: what remotes are, origin vs upstream, listing, adding, changing, renaming and removing remotes, inspecting a remote, remote-tracking branches, ahead and behind, upstream tracking, and remotes in a fork workflow.
🌐 What Is a Remote?
So far your repository lives only on your computer. A remote is another copy of the same repository, usually on a server such as GitHub, that you can send commits to and receive commits from. Remotes are how teams share work and how your code is backed up.
A local repository can have several remotes. Each has a short name and a URL.
| Name | Points to | Typical use |
|---|---|---|
origin | The repository you cloned from, or your main GitHub repository | Push and pull your work |
upstream | The original project you forked | Get updates from the original project (forks) |
origin and upstream are only conventions; you could name a remote anything.
👀 List Your Remotes
git remote # names only
git remote -v # names and URLs
origin git@github.com:asha-verma-qa/git-practice.git (fetch)
origin git@github.com:asha-verma-qa/git-practice.git (push)
A repository created with git init has no remotes. A cloned repository automatically has origin.
➕ Add a Remote
Create an empty repository on GitHub (no README, .gitignore or licence), copy its URL, then:
git remote add origin git@github.com:asha-verma-qa/git-practice.git
git remote -v
Use the HTTPS URL (https://github.com/...) if you have not set up SSH keys.
✏️ Change, Rename or Remove a Remote
git remote set-url origin https://github.com/asha-verma-qa/git-practice.git # switch SSH to HTTPS (or the reverse)
git remote rename origin github
git remote remove github
Changing the URL is common when a repository is renamed or moved to another organization, or when you switch between HTTPS and SSH.
🔎 Inspect a Remote
git remote show origin
* remote origin
Fetch URL: git@github.com:asha-verma-qa/git-practice.git
Push URL: git@github.com:asha-verma-qa/git-practice.git
HEAD branch: main
Remote branches:
main tracked
Local branch configured for 'git pull':
main merges with remote main
Local ref configured for 'git push':
main pushes to main (up to date)
🌿 Remote-Tracking Branches
When Git talks to a remote, it remembers the remote’s branches locally as remote-tracking branches, named origin/main, origin/feature-login and so on. They are read-only bookmarks of “where the remote was the last time I checked”.
git branch -r # remote-tracking branches
git branch -a # local and remote-tracking branches
git branch -vv # local branches with their upstream and ahead/behind counts
* main 8b1d4e2 [origin/main: ahead 2] Add learning goals and initial test plan
“Ahead 2” means you have two local commits that are not on GitHub yet. “Behind 3” would mean GitHub has three commits you have not pulled.
Upstream (tracking) branch
A local branch can track a remote branch, its upstream. Then plain git push and git pull know where to go. You set it with git push -u (next lesson) or manually:
git branch --set-upstream-to=origin/main main
🍴 origin and upstream with Forks
When you contribute to someone else’s project, you usually fork it on GitHub and clone your fork:
git clone git@github.com:asha-verma-qa/playwright-demo.git # your fork = origin
cd playwright-demo
git remote add upstream https://github.com/original-org/playwright-demo.git
git fetch upstream # get the original project's updates
The full fork workflow is in Fork a Repository and Contribute to Open Source.
📝 Assignment
- Create an empty
git-practicerepository on GitHub and add it asoriginto your localgit-practicerepository. - Run
git remote -vandgit remote show origin(after the first push in the next lesson). - Switch the remote URL from SSH to HTTPS and back with
git remote set-url. - Rename
origintogithuband back. - Run
git branch -vvbefore and after making a local commit and explain “ahead”.
❓ FAQ
🤔 What is origin in Git?
The default name for the remote repository you cloned from or added first, usually your repository on GitHub.
🤔 What is the difference between origin and upstream?
origin is usually your own copy (often a fork). upstream is the original project you forked from, used to bring its latest changes into your fork.
🤔 How do I change the remote URL in Git?
git remote set-url origin <new-url>, then check with git remote -v.
🤔 What is origin/main?
A remote-tracking branch: Git’s local record of where main was on origin the last time you fetched or pulled.
🤔 How do I see all branches including remote ones?
git branch -a lists local and remote-tracking branches.
🎯 Next Steps
- 📤 git clone, push and pull Step by Step
- ⚖️ git fetch vs git pull
- 📘 Git and GitHub Tutorial: full course
🎬 Learn Git and GitHub step by step: watch the series on YouTube!
Subscribe to SqaToolsByDY • Practice on sqatools.in
1 thought on “Git Remote Explained: origin, upstream and Remote-Tracking Branches”