Git
Fork
Clone
Push
Version Control

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.

Browse interview questions

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:

  • upstream points to the original project owned by maintainers
  • origin points 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.

bash
git remote -v

Typical output in this scenario looks like this:

text
origin  [email protected]:maintainer/project.git (fetch)
origin  [email protected]:maintainer/project.git (push)

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.

bash
git remote rename origin upstream
git remote add origin [email protected]:your-user/project.git
git remote -v

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.

bash
1git checkout -b fix/login-timeout
2git add .
3git commit -m "Fix timeout handling in login flow"
4git push -u origin fix/login-timeout

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.

bash
1git checkout main
2git fetch upstream
3git merge upstream/main
4git push origin main

If your team prefers rebasing:

bash
1git checkout main
2git fetch upstream
3git rebase upstream/main
4git push --force-with-lease origin main

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 main or 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:

bash
git remote get-url --push origin
git branch -vv

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 origin for your fork and upstream for original repo.
  • Push feature branches with git push -u origin branch-name.
  • Regularly sync main from upstream and mirror it to your fork.
  • Verify remote URLs before pushing to avoid accidental destination mistakes.

Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Basis Lab
No 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 course
Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions