简体   繁体   中英

How do I turn a git clone into a fork and then push to heroku from the fork?

I cloned a repository thinking I wouldn't need to change anything. Now I want to change something.

I forked the code on github but now I'm unsure what to do next. I don't want to make the changes and then then accidentally commit to the repo I cloned from.

Your local git repository determines where to push / pull based on "remotes". Right now, your local repository two remotes, origin (which right now points to the Github repository you cloned) and heroku (which points to a Heroku repository).

You forked the origin to a new repository on Github; let's say the the old one was https://github.com/bob/website.git and your fork is https://github.com/pixelfairy/website.git .

If you do

git remote -v

You should see something like

origin  https://github.com/bob/website.git (fetch)
origin  https://github.com/bob/website.git (push)
...

We can change this so that origin points to your fork. Do

git remote set-url origin https://github.com/pixelfairy/website.git

Now git remote -v should output

origin  https://github.com/pixelfairy/website.git (fetch)
origin  https://github.com/pixelfairy/website.git (push)
...

You can now push and pull as you did before, and it will use your fork instead of the originally cloned repository.

Just to add to @tbekolay answer, if needed, you can still fetch / pull from the original branch that was cloned in order to keep up with changes from there. Do this by adding an "upstream" ( or other named ) remote that still points to the original remote ( bob in this case ).

git remote add upstream https://github.com/bob/website.git

Then you can update your code by pulling from there from time to time:

git pull upstream <branch name>

If you ever want to change the new remote use:

git remote set-url upstream <new url>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM