2

I forked from a git repo and did some developments. Also the original repo had some progresses. I want to merge it to my repo. I don't want to push anything to original repo. I just want to pull their changes to mine and continue development on my repo.

0

2 Answers 2

4

Ah ok in the meantime I think I guessed what you mean with forked. According to your question-tags you forked on github! Right?

Ok then it is easy. A fork on github is basically a clone of the repository where you pressed the fork button.

To reconnect to the original repository you do the following steps on your local machine:

As Example and to try out I have forked libgit2 for this...

$ git clone https://github.com/MyOwnAccount/libgit2.git
Cloning into 'libgit2'...
remote: Counting objects: 43058, done.
remote: Compressing objects: 100% (16412/16412), done.
remote: Total 43058 (delta 30556), reused 37875 (delta 25761)
Receiving objects: 100% (43058/43058), 12.22 MiB | 942 KiB/s, done.
Resolving deltas: 100% (30556/30556), done.
Checking out files: 100% (2432/2432), done.

$ git remote -v
origin  https://github.com/MyOwnAccount/libgit2.git (fetch)
origin  https://github.com/MyOwnAccount/libgit2.git (push)

$ git remote add forkOrigin https://github.com/libgit2/libgit2.git

$ git remote -v
forkOrigin https://github.com/libgit2/libgit2.git (fetch)
forkOrigin https://github.com/libgit2/libgit2.git (push)
origin  https://github.com/MyOwnAccount/libgit2.git (fetch)
origin  https://github.com/MyOwnAccount/libgit2.git (push)

$ git fetch forkOrigin 

$ git fetch --tags forkOrigin 

Now you have all the latest commits, branches and tags from the repo where you forked. (You could use rebase or merge directly on the remote branches - do just as you like/need at this point, fetch was just the easiest way to show now)

With this fetched data you can merge, rebase, cherry-pick etc. as usual.

If you later on push the changes to your own repository you are done.

1
  • Did this help you Milad? Then you can accept the answer. Otherwise please ask. Best of luck with your project! Nov 24, 2013 at 5:14
0

If you used GitHub as the github of your post suggests, then you probably forked the original repo to your GitHub account, and then cloned from your fork. You could have cloned from the original repo instead of your fork, but I will assume the first case.

When you clone from your fork, git automatically creates a remote for it called origin. To get the changes from the original repo, first you have to add a remote for it, let's call it other:

git remote add other the_github_url

Next, get the branches of this repo:

git fetch other

You can use the same command later to get the new changes committed in that repo.

You can view the branches in the other remote with:

git branch -r

You can merge the master of the other remote into your current branch with:

git merge other/master

That is, you use the name of the remote followed by a slash and then the name of the branch.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.