Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to move to a fork after cloning
So you've cloned somebody's repo from github, but now you want to fork it and contribute back. Never fear!
Technically, when you fork "origin" should be your fork and "upstream" should be the project you forked; however, if you're willing to break this convention then it's easy.
* Off the top of my head *
1. Fork their repo on Github
2. In your local, add a new remote to your fork; then fetch it, and push your changes up to it
git remote add my-fork git@github...my-fork.git
git fetch my-fork
git push my-fork
Otherwise, if you want to follow convention:
1. Fork their repo on Github
2. In your local, rename your origin remote to upstream
git remote rename origin upstream
3. Add a new origin
git remote add origin git@github...my-fork
4. Fetch & push
git fetch origin
git push origin
@Stuart-N
Copy link

Thanks!

@Justin2997
Copy link

Thanks !

@sslupsky
Copy link

sslupsky commented May 8, 2019

Thank you. :-)

@DanielRiezebos
Copy link

Thank you very much!

@alex-che
Copy link

Isn't the simplest way to switch to your fork being the new remote origin just like this?

git remote set-url origin https://github.com/myusername/myrepo.git

(After that, git push pushes to your fork. Done.)

This.

@ViralTaco
Copy link

You legend <3

@sungjae-cho
Copy link

Wonderful! Thank you!

@aseevia
Copy link

aseevia commented Jan 15, 2020

Thanks!

@neoVincent
Copy link

Thanks!

@tabarnakos
Copy link

Thanks man. Used to SVN but new to git.

@tabarnakos
Copy link

I followed your "convention" instructions and they worked!

However, to allow me to just perform git push to push updates to my fork, I had to perform the following command:

git push -u origin branchname

Without performing the push -u a simple git push tried to push to the upstream repo.
👍 for @HeatfanJohn

@Rmano
Copy link

Rmano commented Apr 24, 2020

Thanks!

@ericsson49
Copy link

Thanx a lot!

@OGALI
Copy link

OGALI commented Jun 5, 2020

Perfect 👍

@HatHeadNinja
Copy link

Thank you!!!

@nir-logzio
Copy link

Nice!

@maniSHarma7575
Copy link

Thanks a lot! Worked for me

@diregraph
Copy link

Thanks!

@doronz2
Copy link

doronz2 commented Nov 9, 2020

Thanks a lot!

@sujayvadlakonda
Copy link

Thank you!

@jayleekr
Copy link

jayleekr commented Jan 2, 2021

Thanks man this is really helpfull

@mikeschinkel
Copy link

YATYC!

@clmcavaney
Copy link

Thanks 👍

@lesywix
Copy link

lesywix commented Aug 8, 2021

Thanks!

@ripudaman17
Copy link

Thanks a lot

@Bug-Reaper
Copy link

Still good, thanks 👍

@flipphillips
Copy link

You know what's hilarious? I literally searched for the opening sentence in this gist.

More people should open their help with "So you want to ... X" :)

@Jaspreet9795
Copy link

Thank you ! Couldn't find this straight answer anywhere else.

@jeremiahgivens
Copy link

Wonderfully straight forward and helpful!

@TomasHubelbauer
Copy link

TomasHubelbauer commented Jan 20, 2023

⚠️ Easier solution alert ⚠️

  • Download and install https://cli.github.com
  • Run gh repo fork in the repository you cloned that isn't yours
  • Allow the tool to update origin
  • Make your changes and push
  • Select origin as your desired upstream, upstream is a new origin pointing to the original fork's repo!

https://cli.github.com/manual/gh_repo_fork

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment