refusing to merge Suggested histories
The problem
1. Initialize git repository locally, put some files in it, and perform add and commit operations;
$ git add -A
$ git commit -m "start 2018-06-06"
Copy the code
Github creates git repository and README file.
Add git repository on Github as remote repository and name it Origin.
$ git remote add origin https://github.com/tielemao/TielemaoMarkdown
Copy the code
4, the local repository is trying to synchronize the remote repository to the local repository in preparation for the remote repository push. The error is as follows:
Fatal: refusing to merge suggested histories
To solve
The main reason for this problem is that the local and remote warehouses are actually separate repositories. This would not have been the case if I had cloned the github repository locally.
After looking through the resources, it was possible to solve the problem using the — Allow-suggested -history option right after the pull command (the option can merge the histories of two independently launched warehouses).
Command:
$ git pull origin master --allow-unrelated-histories
Copy the code
The above is to pull the files from the remote warehouse to the local warehouse. Then push the commit from the local repository to the remote Github repository using the following command:
$git push $git push $git pushCopy the code
That is
$git push origin master:master
Copy the code
The submission is successful.
pull
Git pull is basically a combination of git fetch and Git merge. Git grabs content from a designated remote repository and then immediately attempts to merge it into your branch.
To obtain data from a remote repository, perform:
$ git fetch [remote-name]
Copy the code
This command accesses the remote repository and pulls any data from it that you don’t already have. When the execution is complete, you will have references to all branches in that remote repository that can be merged or viewed at any time.
Note, however, that Git Fetch does not automatically merge or modify your current work. You must manually incorporate it into your work when it is ready.
If you clone a repository using the Clone command, the command automatically adds it to the remote repository and defaults to “Origin”. So git Fetch Origin grabs all the new push work since the clone (or last fetch).
Since the fetch command is followed by the merge command, git pull is used to automatically fetch and merge remote branches into the current branch. (equivalent to executing fetch plus merge at once.) This could be a simpler or more comfortable workflow.