I'm learning git, and I'm following the Git community book.

Previously (long time ago) I made a public repository on Github, with some files. Now I set up a local Git repository on my current computer, and committed some files. Then I added a remote pointing to my Github page:

[root@osboxes c]# git remote add learnc https://github.com/michaelklachko/Learning-C

That seemed to be successful:

[root@osboxes c]# git remote show learnc
* remote learnc
  Fetch URL: https://github.com/michaelklachko/Learning-C
  Push  URL: https://github.com/michaelklachko/Learning-C
  HEAD branch: master
  Remote branch:
    master tracked
  Local ref configured for 'git push':
    master pushes to master (local out of date)

Now I want to download the files from my Github repo to my computer. I did this:

[root@osboxes c]# git fetch learnc
[root@osboxes c]# git merge learnc/master
warning: refname 'learnc/master' is ambiguous.
Already up-to-date.

However, I don't see any new files in my local directory. How can I get them?

I also tried to do this:

[root@osboxes c]# git pull learnc master
From https://github.com/michaelklachko/Learning-C
 * branch            master     -> FETCH_HEAD
fatal: refusing to merge unrelated histories

BTW, locally I'm on master branch (there are no other branches):

[root@osboxes c]# git status
On branch master
nothing to commit, working directory clean
share|improve this question
2  
When you set up your local repo, did you clone your Github repo or just did git init? In the latter case those repos are unrelated (have no common commits) and you can't merge them (pull is fetch+merge). – Paul Jul 7 '16 at 21:40
    
I did git init. So should I clone my Github repo to fix this? – MichaelSB Jul 7 '16 at 21:41
    
You can clone your Github repo and continue work with it, but it'll still be separate repo. Do you want to merge two unrelated histories together? – Paul Jul 7 '16 at 21:42
    
I guess I want to merge histories, but really I just want to combine files both locally and on github. I mean I don't really care about history of the old files I have on Github. – MichaelSB Jul 7 '16 at 21:44
2  
stackoverflow.com/a/36528527/2303202 – max630 Jul 10 '16 at 12:58
up vote 65 down vote accepted

Try --allow-unrelated-histories

Like max630 commented, or as explained here Git refusing to merge unrelated histories

share|improve this answer
    
as noted on the github release notes – systemaddict Sep 12 '16 at 9:44
git checkout master
git merge origin/master --allow-unrelated-histories

Resolve conflict, then

git add -A .
git commit -m "Upload"
git push
share|improve this answer

If there is not substantial history on one end (aka if it is just a single readme commit on the github end), I often find it easier to manually copy the readme to my local repo and do a git push -f to make my version the new root commit.

I find it is slightly less complicated, doesn't require remembering an obscure flag, and keeps the history a bit cleaner.

share|improve this answer

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.