8

So I originally cloned a repo thinking I wouldn't make changes and eventually decided to fork my own copy for personal use (it's a dotfiles repo). If I want to continue changes from the fork, what's the cleanest way to copy local commits from the original clone over to the forked repo?

Looked around and couldn't find exactly what I want here.

Clarification:

I have two repos now on my computer, one that's a clone of the original repo, and another a fork from the same repo. I made changes to the clone, but am hoping to move these local commits over to the fork.

Justian Meyer
  • 3,623
  • 9
  • 35
  • 53

2 Answers2

6

The usual way to do this would be with git pull, just as you would when you want to merge any commits from another repo.

Caleb
  • 124,013
  • 19
  • 183
  • 272
  • Not sure this is what I'm looking for. Are you saying I could/should just pull the commits from my cloned repo into my forked one? Is this possible locally? – Justian Meyer Sep 24 '15 at 19:05
  • I'm still not getting what you're suggesting. I didn't think you could pull across repos because of the way git manages changes. Are you saying it should work in this case? Something similar to http://stackoverflow.com/questions/4131164/pulling-from-another-local-repository, except with 2 different repos and without the need to ssh? – Justian Meyer Sep 24 '15 at 19:17
  • 6
    Huh, well I guess it was that simple. Going to poke around a little more to confirm, but I think this is as good as solved. For history: `git pull /path/to/cloned/repo` in the forked repo did the trick. – Justian Meyer Sep 24 '15 at 19:23
  • 1
    A fork and a repo are [almost the same thing](http://stackoverflow.com/questions/7057194/what-is-the-difference-between-forking-and-cloning-on-github), so you're really just talking about moving commits from one to the other, just as you would with any two repos. – Caleb Sep 24 '15 at 19:41
2

Let's say you have main Repo as R, Original clone as C and current Fork as F. You want to get changes from C into F, without disturbing R.

You can achieve this by setting a remote upstream and syncing your fork.

Step1. To set upstream refer: https://help.github.com/articles/configuring-a-remote-for-a-fork/ Sitting in the branch of F, you can set upstream(or name it anything else you want to) to C. run:

git checkout <branch of F>
git remote add upstream <repo URL for C>
git remote -v

Step2. Syncing your fork. Refer: https://help.github.com/articles/syncing-a-fork/ run:

git checkout <branch of F>
git fetch upstream
git merge upstream/<branch of C>

This should bring changes from C into F. Just make sure you ensure the right branches are mentioned in the git commands.

codePrady
  • 110
  • 7