How can I push to my fork from a clone of the original repo?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
If you cloned the original repository but want to push your changes to your own fork, you only need to fix remote configuration. Git does not care where you cloned from as long as remotes are set correctly. The usual pattern is keeping the original repo as upstream and your fork as origin.
Understand the Remote Model
In fork-based workflows, two remotes are common:
upstreampoints to the original project owned by maintainersoriginpoints to your fork where you push branches
If you cloned the original repo directly, your current origin usually points to upstream. That is why push attempts fail or go to the wrong place.
Inspect Current Remotes
Start by checking current remote URLs.
Typical output in this scenario looks like this:
You need your fork URL added and usually set as origin.
Reconfigure Remotes to Target Your Fork
Option one is to rename existing origin to upstream, then add your fork as new origin.
After this, your pushes default to your fork while pulls from maintainers can still use upstream.
Option two is keeping names as-is and pushing explicitly to fork remote each time. This works, but standard naming is easier for teams and scripts.
Push a Feature Branch to Your Fork
Create and push a branch from your local clone.
The -u flag sets upstream tracking so later git push and git pull commands can omit branch and remote names.
Keep Your Fork Synced with Upstream
Before starting new work, sync your main branch from original project.
If your team prefers rebasing:
Use force push carefully and only on branches where rewriting history is acceptable.
Open Pull Requests Correctly
After pushing branch to your fork, open a pull request where:
- base repository is upstream project
- base branch is usually
mainor maintainers' target branch - compare branch is your fork branch
This keeps collaboration clean and avoids accidentally opening PRs from stale branches.
Working with Existing Local Clones
If local history already contains work, remote changes do not lose commits. Remotes only control where fetch and push happen. You can safely reconfigure remotes at any time and continue using your current branch history.
To verify push destination before publishing sensitive changes:
These checks prevent accidental pushes to protected upstream repositories.
Common Pitfalls
A frequent mistake is leaving upstream as origin and running plain git push, which either fails due permissions or targets the wrong remote. Another issue is forgetting branch tracking setup, leading to repeated full push commands and confusion. Developers also sometimes fetch only from origin and wonder why maintainer updates are missing, because upstream was never configured. Finally, force-pushing shared branches without coordination can overwrite collaborators' commits.
Summary
- You can push to your fork from any clone by configuring remotes correctly.
- Recommended setup is
originfor your fork andupstreamfor original repo. - Push feature branches with
git push -u origin branch-name. - Regularly sync
mainfrom upstream and mirror it to your fork. - Verify remote URLs before pushing to avoid accidental destination mistakes.
Related reading
- How can I put a database under git version control?
- How can I reconcile detached HEAD with master/origin?
- How can I recover a lost commit in Git?
- How can I remove a Git branch locally?
- How can I remove a GitLab project?
- How can I remove an entry in global configuration with git config?
- How can I Remove .DS_Store files from a Git repository?
- How can I remove file from Git history?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseNo course covers this one yet
Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.
Build my courseInterview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.