Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Let's say that I've created a clone http://code.google.com/r/kkowalczyk-leveldb of http://code.google.com/p/leveldb using web interface on code.google.com

Since the time I created my clone, there were changes made to http://code.google.com/p/leveldb and I would like to merge them to my clone, preferably preserving history (i.e. I could merge them manually using a diff/merge tool, but that doesn't preserve git history).

What are the magic commands to perform such merge?

Preferably please provide the complete commands. I imagine it'll involve some combination of git fetch and git merge and remote-tracking branches etc. My problem is not that I can't read man pages for git fetch or merge, I just don't understand them.

Update:

Given Lazy Badger's comment below, I've solved half of the issue:

git remote add original https://code.google.com/p/leveldb/

Creates something called 'original' pointing to the source. I can then do:

git pull original master

Which fetches and merges changes from original into my branch master. I would, however, to do it in 2 separate steps: as git fetch and git merge $something to merge into my current branch.

However, after git fetch original, I don't know what $something would be. When I do git branch -a, I don't see anything related to my remote original thingy.

What complicates things is that there are 3 branches in original as well.

So, where do data fetched from original go and how should I refer to it in my git merge $something?

share|improve this question
    
This is a duplicate of stackoverflow.com/questions/1425892/… –  polynomial Oct 6 '11 at 2:42
    
Answer [found here][1], just small googling. [1]: stackoverflow.com/questions/4313125/… –  Lazy Badger Oct 6 '11 at 3:53
    
Please see the update. Those don't really answer my questions. –  Krzysztof Kowalczyk Oct 6 '11 at 7:07

2 Answers 2

up vote 2 down vote accepted

You already found how to add another remote and pull directly from it:

git remote add original https://code.google.com/p/leveldb/
git pull original master

If you want to do the fetch and merge separately (instead of a single pull command; maybe because you want to inspect what changed before merging it), then you can do that like this:

git fetch original         # update refs/remotes/original/*
git merge original/master  # merge refs/remotes/original/master

You might inspect the changes before merging with this command:

git log --reverse -p original/master@{1}..original/master@{0}

Instead of using the above reflog-based revision specification, you could also just copy-and-paste the oldhash..newhash revision specification that was output during the fetch.


Technically, git pull remote branch is closer to this pair of commands:

git fetch remote-or-url branch  # grab remote branch and put it in FETCH_HEAD
git merge FETCH_HEAD            # merge it

but this pair (and thus also pulling with both a remote and a branch specified) is usually not as nice since it does not update the remote-tracking branches (refs/remotes/original/*). The remote+branch invocations of fetch and pull are useful for one-off merges from repositories for which you do not particularly want to keep a full set of remote-tracking branches (i.e. fetching/pulling a merge request from a minor/rare contributor).

share|improve this answer

You can add multiple remotes to a single repository. Once you've got the second remote, you can simply push the changes of the first to the second. For example:

git clone <google_URI>
cd <projdir>
git remote add github <github_URI>
git push github master
share|improve this answer
    
That doesn't answer my question - see the update. What I want to know: after git remote add github <github_URI> followed by git fetch github, what is <sth> in git merge <sth>, assuming that github remote has 2 branches, e.g. master and win. –  Krzysztof Kowalczyk Oct 6 '11 at 8:01
    
Chris' answer below shows the shomething: FETCH_HEAD or original/master would do. Or you could create another local branch from either of the two, and merge from there. –  Dysaster Oct 6 '11 at 10:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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