I have installed Github desktop and git on windows machine, I got a github account and created a dummy repository.

When I intend to upload my package through git bash command line, it fails with error: fatal: refusing to merge unrelated histories

I used several ways to overcome this issues by using existing solution from this community, but still didn't fix the problem. Does anyone know any trick of working this problem? How can I upload my projects to github successfully?

share|improve this question
up vote 2 down vote accepted

Try the following:

cd /path/to/my/repo
git init
git add --all
git commit -m "Initial commit"
git remote add origin <remote repo URL>
git push -u origin master

Be sure to replace /path/to/my/repo with path to your repo directory(e.g. C:\Users\jvrat\Documents\MSPC), and <remote repo URL> with URL to your remote repo (e.g. https://github.com/username/repo_name.git).

share|improve this answer
    
can't finish rm -r .git command yet. Plus, git add all gave me an error. Any further solution ? – Jerry Nov 9 '16 at 1:09
    
Does the error message say anything more? You can try this solution – TeWu Nov 9 '16 at 1:38
    
your solution is quite helpful, the last comment is useful. Thank you :) – Jerry Nov 9 '16 at 1:50
    
Plus, where can I find useful git command when I am interacting github if any new commit is taken place ? Any useful git command you could recommend ? Thanks your big help :) – Jerry Nov 9 '16 at 1:57
    
Just google "git tutorial", and you'll find a lot of them. Github has its own interactive git tutorial too. For reference purposes it's best to use official git docs. – TeWu Nov 9 '16 at 2:18

The first step is to init git inside your local project directory:

git init

After that your directory is a local git repository and contains a .git directory. You then basically create files and add it to your repo via

git add <file-name>

Files added to your repo are tracked now. If you want to commit all the changes you made to the files you added you just need to

git commit "Commit message"

These all resides on your local git repo. To connect your local repo to a remote one you have to issue another command:

git remote add origin <remote repo URL>

'origin' and the following URL represent remote name and its URL. You are now able to push your local changes to your origin repo via

git push <remote-name> <branch-name>

which is in your case

git push origin master

because for now you just have a master branch.

You can check the status of your local repo and its connected remote repo via

git status
share|improve this answer
    
Try a 'git pull' to incorporate changes from your remote repo first. – habaMedia Nov 9 '16 at 1:30
    
still can't solved. Could you give me alternative solution please ? – Jerry Nov 9 '16 at 1:40
    
Just create a new folder, navigate to it via CLI and issue a 'git clone <repo-URL>' after that just issue 'git init'. You now have local git repo in sync with your origin. – habaMedia Nov 9 '16 at 1:43

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.