Git Remote Explained: Origin, Upstream & Remote Commands
80 people viewed this
Git Remote Explained — Origin, Upstream and Remote Repository Commands
When you work with Git in a professional PHP or Laravel project, your code usually exists in two places:
Your Local Repository
↕
Remote Repository
The connection between your local Git repository and a remote repository is managed using Git remotes.
You will commonly see commands such as:
git remote -v
git remote add
git remote remove
git remote rename
git remote set-url
You will also frequently hear:
origin
upstream
In this article, we will understand Git Remote from beginner to practical level, with PHP/Laravel and Bitbucket examples.
1. What Is a Git Remote?
A Git remote is a named reference to another Git repository.
That repository is usually hosted somewhere outside your local machine, such as:
- Bitbucket
- GitHub
- GitLab
- A company's private Git server
For example:
Local Laravel Project
↓
origin
↓
Bitbucket Repository
The remote gives Git the URL it should use when fetching or pushing data.
2. Why Do We Need Git Remotes?
Without a remote repository, your Git repository could still track changes locally, but you would not have the same built-in connection to a shared remote repository.
A remote allows developers to:
- Push local commits
- Fetch remote commits
- Pull changes
- Collaborate with teammates
- Back up project history on a remote server
- Work with Pull Requests
- Synchronize branches
For example:
git push origin maingit fetch origingit pull origin develop
3. What Is origin?
origin is the conventional default name Git gives to the remote repository when you clone a repository.
For example:
git clone https://bitbucket.org/company/pharmacy-erp.git
Git normally creates a remote named:
origin
You can check it with:
git remote -v
Example:
origin https://bitbucket.org/company/pharmacy-erp.git (fetch)
origin https://bitbucket.org/company/pharmacy-erp.git (push)
Important: origin is just a conventional remote name. It is not a special keyword that must always be used.
4. Is origin the Same as the Remote Repository?
Not exactly.
The remote repository is the actual repository hosted somewhere.
origin is the local name your Git configuration uses to refer to that repository.
For example:
origin
↓
https://bitbucket.org/company/pharmacy-erp.git
You could call the remote something else:
company-repo
But origin is the standard convention after cloning.
5. Check Your Git Remotes
The most commonly used command is:
git remote -v
Example:
origin git@bitbucket.org:company/pharmacy-erp.git (fetch)
origin git@bitbucket.org:company/pharmacy-erp.git (push)
This shows:
- Remote name
- Fetch URL
- Push URL
6. git remote Without Options
Run:
git remote
You may get:
origin
If multiple remotes exist:
origin
upstream
company
This command only shows the remote names.
For URLs, use:
git remote -v
7. git remote -v Explained
The -v option means verbose output.
git remote -v
Example:
origin https://bitbucket.org/company/project.git (fetch)
origin https://bitbucket.org/company/project.git (push)
The two entries represent the URLs Git uses for fetching and pushing.
Often they are the same, but Git supports configurations where the fetch and push URLs differ.
8. Add a New Remote
You can add another remote using:
git remote add <name> <url>
For example:
git remote add upstream https://github.com/company/project.git
Now check:
git remote -v
You might see:
origin https://github.com/bikram/project.git (fetch)
origin https://github.com/bikram/project.git (push)
upstream https://github.com/company/project.git (fetch)
upstream https://github.com/company/project.git (push)
9. What Is upstream?
In a fork-based workflow, developers commonly use the name upstream for the original repository from which their fork was created.
For example:
origin
↓
Your Fork
upstream
↓
Original Repository
This is a convention, not a special Git keyword.
10. Origin vs Upstream
| origin | upstream |
|---|---|
| Common default remote name after clone | Common name for the original repository in a fork workflow |
| Often points to your fork or the repository you cloned | Often points to the original project |
| Commonly used for pushing your work | Commonly used for fetching original-project updates |
| Not a special Git keyword | Not a special Git keyword |
The exact meaning depends on how your repository is configured.
11. Git Remote in a Fork Workflow
Suppose you fork an open-source Laravel project.
Original Repository
↓
Your Fork
↓
Local Repository
You may configure:
origin → Your Fork
upstream → Original Repository
Check:
git remote -v
Then:
git fetch upstream
gets updates from the original repository into your local remote-tracking references.
You can push your work to:
git push origin feature/my-feature
12. Add Upstream to an Existing Repository
Suppose you cloned your fork:
git clone https://github.com/bikram/laravel-package.git
Your origin points to your fork.
Add the original repository:
git remote add upstream https://github.com/company/laravel-package.git
Verify:
git remote -v
13. Fetch From a Remote
You can fetch from a specific remote:
git fetch origin
Or:
git fetch upstream
This updates your local knowledge of that remote's branches without automatically integrating those changes into your current branch.
14. Push to a Remote
To push a branch:
git push origin main
Or a feature branch:
git push origin feature/payment
In a fork workflow, this commonly means:
git push origin feature/payment
because origin points to your fork.
15. Pull From a Remote
You can also specify the remote when pulling:
git pull origin main
This fetches from origin and then integrates the fetched changes into the current branch according to the pull strategy/configuration.
16. Change a Remote URL
Suppose your project moved to a different repository URL.
You can update the remote:
git remote set-url origin <new-url>
Example:
git remote set-url origin git@bitbucket.org:company/new-project.git
Verify:
git remote -v
17. HTTPS to SSH Migration
Suppose your current remote is:
origin https://bitbucket.org/company/project.git
You want to use SSH instead.
Run:
git remote set-url origin git@bitbucket.org:company/project.git
Then verify:
git remote -v
Your Git remote configuration is now using the SSH URL.
18. Rename a Remote
You can rename a remote:
git remote rename <old-name> <new-name>
For example:
git remote rename origin company
Now:
git remote
may show:
company
Be aware that changing a remote name can also affect local branch configuration that references that remote, so verify your tracking configuration afterward.
19. Remove a Remote
If a remote is no longer needed:
git remote remove upstream
Or:
git remote rm upstream
Then:
git remote -v
The remote is removed from your local Git configuration.
Important: removing a remote does not delete the actual repository hosted on Bitbucket, GitHub, or another server.
20. Get the URL of One Remote
You can retrieve a specific remote's URL:
git remote get-url origin
Example output:
git@bitbucket.org:company/pharmacy-erp.git
You can also inspect:
git remote get-url upstream
21. Fetch URL vs Push URL
Git can maintain separate fetch and push URLs.
To see them:
git remote -v
You might see:
origin https://example.com/project.git (fetch)
origin git@example.com:project.git (push)
This is an advanced configuration, but it is useful to understand because git remote -v explicitly shows both.
22. Remote-Tracking Branches
When you fetch a remote, Git maintains remote-tracking references such as:
origin/main
origin/develop
origin/feature/payment
These represent the last fetched state of the corresponding remote branches.
For example:
main
origin/main
These are not the same thing.
main— your local branchorigin/main— your local remote-tracking reference
23. List Remote Branches
To see remote-tracking branches:
git branch -r
Example:
origin/main
origin/develop
origin/feature/payment
origin/feature/inventory
To see local and remote branches:
git branch -a
24. Remote vs Remote-Tracking Branch
These two concepts are often confused.
Remote:
origin
This is a named connection/reference to a repository.
Remote-tracking branch:
origin/main
This is a local reference that records the last fetched state of the remote's main branch.
25. Tracking Branches
A local branch can be configured to track a remote branch.
For example:
main → origin/main
Then commands such as:
git pull
git push
can use the configured upstream/tracking information without requiring you to specify the remote and branch every time.
You can inspect tracking information with:
git branch -vv
Example:
* main a82d921 [origin/main] Add payment service
develop b91c441 [origin/develop] Update inventory
26. What Does git push -u Do?
Suppose you create:
git switch -c feature/payment
Push it:
git push -u origin feature/payment
The -u option establishes tracking between your local branch and the remote branch.
After that, you can often use:
git push
git pull
without specifying the remote and branch every time.
27. Practical Laravel Example — Bitbucket Repository
Suppose your Laravel application is hosted in Bitbucket:
git@bitbucket.org:company/pharmacy-erp.git
Clone it:
git clone git@bitbucket.org:company/pharmacy-erp.git
Enter the project:
cd pharmacy-erp
Check the remote:
git remote -v
Output:
origin git@bitbucket.org:company/pharmacy-erp.git (fetch)
origin git@bitbucket.org:company/pharmacy-erp.git (push)
Create your feature branch:
git switch -c feature/payment-report
Make Laravel changes and commit:
git add .
git commit -m "feat(payment): add payment report"
Push:
git push -u origin feature/payment-report
Your branch is now associated with the remote branch.
28. Practical Fork + Upstream Example
Suppose you fork a Laravel project.
Your setup is:
origin
↓
Your Fork
upstream
↓
Original Project
Check:
git remote -v
Fetch original changes:
git fetch upstream
Update your local main branch according to your workflow:
git switch main
git merge upstream/main
Then push the updated branch to your fork:
git push origin main
29. Multiple Git Remotes
Git supports multiple remotes.
For example:
origin
upstream
backup
You might have:
origin → Bitbucket
upstream → Original GitHub project
backup → Internal backup repository
Check all of them:
git remote -v
This can be useful in advanced workflows, migrations, or projects mirrored across multiple hosting platforms.
30. Git Remote for a Repository Migration
Suppose your project moves from one Git hosting service to another.
Old:
origin → old-server/project.git
New:
origin → new-server/project.git
Update it:
git remote set-url origin <new-url>
Verify:
git remote -v
Then test the connection using an appropriate fetch or other non-destructive operation:
git fetch origin
31. Check Remote Details
For more detailed information about a remote:
git remote show origin
This can show information such as:
- Remote URLs
- Remote branches
- Tracked branches
- Push/pull information
- Local branches configured against the remote
This is useful when troubleshooting remote configuration.
32. Common Git Remote Errors
❌ Error 1 — Remote does not exist
You may run:
git fetch upstream
and Git reports that the remote is unknown.
Check:
git remote -v
If necessary, add it:
git remote add upstream <url>
❌ Error 2 — Wrong remote URL
Check:
git remote get-url origin
If incorrect:
git remote set-url origin <correct-url>
❌ Error 3 — Permission denied
The remote URL may be correct but your authentication or repository permissions may not allow the requested operation.
Check:
git remote -v
Then verify that your SSH key, HTTPS authentication method, and repository permissions are correctly configured according to your hosting platform.
❌ Error 4 — Push rejected
A push can be rejected because the remote branch contains commits your local branch does not have, or because branch permissions/protection prevent the push.
Inspect:
git fetch origin
git status
git log --oneline --decorate --graph --all
Then follow the repository's branch and integration policy.
33. Git Remote Best Practices
- Use clear remote names.
- Understand what
originpoints to before pushing. - In fork workflows, clearly distinguish
originandupstream. - Check
git remote -vwhen troubleshooting. - Use
git fetchwhen you want to inspect remote updates before integrating them. - Keep remote URLs correct after repository migrations.
- Don't remove a remote thinking it deletes the remote repository itself.
- Use branch tracking intentionally.
- Follow your team's authentication and repository-access policies.
34. Important Git Remote Commands Cheat Sheet
| Command | Purpose |
|---|---|
git remote |
List remote names |
git remote -v |
Show remote names and URLs |
git remote show origin |
Show detailed information about a remote |
git remote get-url origin |
Show the URL for a remote |
git remote add upstream URL |
Add a remote |
git remote remove upstream |
Remove a remote |
git remote rename old new |
Rename a remote |
git remote set-url origin URL |
Change a remote URL |
git fetch origin |
Fetch from a remote |
git push origin main |
Push a branch to a remote |
git pull origin main |
Fetch and integrate from a remote |
35. Origin vs Upstream — Easy Diagram
ORIGINAL REPOSITORY
│
│ upstream
↓
YOUR FORK
│
│ origin
↓
LOCAL REPOSITORY
In this common fork workflow:
git fetch upstream
↓
Get updates from original project
git push origin feature/payment
↓
Push your work to your fork
36. Company Bitbucket Workflow
In a company project, you may not have an upstream fork relationship at all.
For example:
Bitbucket
│
│ origin
↓
Local Laravel Repository
Typical workflow:
git clone <company-repository>
git switch -c feature/invoice-report
# Make changes
git add .
git commit -m "feat(invoice): add invoice report"
git push -u origin feature/invoice-report
Then the team can review the branch through the company's Pull Request workflow.
37. Git Remote Interview Questions
Q1. What is a Git remote?
A Git remote is a named reference to another Git repository, usually hosted on a remote server.
Q2. What is origin?
origin is the conventional default name assigned to the remote repository when you clone a repository.
Q3. Is origin a special Git keyword?
No. It is a conventional remote name that can be renamed.
Q4. What is upstream?
upstream is a conventional name often used for the original repository in a fork-based workflow.
Q5. How do you check remote URLs?
git remote -v
Q6. How do you add a remote?
git remote add upstream <url>
Q7. How do you change a remote URL?
git remote set-url origin <new-url>
Q8. How do you remove a remote?
git remote remove upstream
Q9. Does removing a remote delete the remote repository?
No. It removes the remote reference from your local Git configuration. It does not delete the repository hosted on the remote server.
Q10. What is the difference between origin and origin/main?
origin is the name of a remote. origin/main is a remote-tracking reference for the remote's main branch.
Q11. How do you see detailed information about origin?
git remote show origin
Q12. How do you push a new branch and set its upstream tracking?
git push -u origin feature/payment
38. Practical Laravel Remote Workflow
Suppose you are developing a Laravel application called:
pharmacy-erp
Clone:
git clone git@bitbucket.org:company/pharmacy-erp.git
Check remote:
git remote -v
Create branch:
git switch -c feature/payment-report
Make Laravel changes.
Run tests:
php artisan test
Commit:
git add .
git commit -m "feat(payment): add payment report"
Push:
git push -u origin feature/payment-report
Fetch future updates:
git fetch origin
Pull the latest branch changes when appropriate:
git pull origin develop
This is a common day-to-day Git workflow for Laravel developers.
39. Easy Way to Remember Git Remote
Remember these five concepts:
REMOTE
↓
Connection to another repository
ORIGIN
↓
Common name for the cloned remote
UPSTREAM
↓
Common name for original repository in fork workflow
FETCH
↓
Get remote updates
PUSH
↓
Send local commits to remote
And the most useful command:
git remote -v
Whenever you are unsure where your code will be pushed or fetched from, check the remotes first.
Conclusion
Git remotes are the connection between your local Git repository and other repositories hosted on services such as Bitbucket, GitHub, and GitLab.
The most important concepts are:
origin— conventional name for the remote you cloned fromupstream— conventional name for the original repository in a fork workflowgit remote -v— inspect remote URLsgit remote add— add a remotegit remote set-url— change a remote URLgit remote rename— rename a remotegit remote remove— remove a remote referencegit fetch— retrieve remote updatesgit push— send commits to a remote
For professional PHP and Laravel development, understanding remotes is essential because most team workflows depend on remote repositories and Pull Requests.
The single command you should remember when troubleshooting remote configuration is:
git remote -v
What's Next?
Now that we understand Git remotes, the next logical topic is how local branches connect to remote branches and how tracking works.
Next Article: Git Tracking Branches & Upstream Branches Explained
We will cover:
- What is a tracking branch?
- What is an upstream branch?
- Local branch vs remote-tracking branch
git branch -vvgit push -ugit branch --set-upstream-to- How
git pullknows which branch to pull - How
git pushknows where to push - Fixing "no upstream branch" errors
- Practical Bitbucket workflow
- Git interview questions
Was this useful?
No ratings yet — yours can be the first.
Discussion
Notes from readers. Comments appear after a short review.
No comments yet. Start the thread below.