Articles → GIT → --Allow-Unrelated-Histories In GIT
--Allow-Unrelated-Histories In GIT
Purpose
What Are Unrelated Branches?
Reproduce Error
- Clone the remote repository on the local machine.
- Delete and recreate the .git folder.
- Connect to the remote repository.
- Add a new file and commit in the local repository.
- Pull from the remote repository.
# Clone the remote repository on the local machine
git clone <URL>
# Delete the .git folder on the local repository.
# Recreate .git folder
git init
# Connect to the remote repository.
git remote add origin <URL>
# Added the file “2.txt”.
# Commit the file in the local repository
git add .
git commit -m “Added 2.txt”
# Try to pull from the remote repository.
# You will get an error while executing this command
git pull
# Set upstream branch
git branch --set-upstream-to=origin/master
# Try to pull from the remote repository.
git pull
Click to Enlarge
How To Fix The Issue?
git pull --allow-unrelated-histories
Click to Enlarge
Click to Enlarge
Click to Enlarge