Articles → GIT → --Allow-Unrelated-Histories In GIT

--Allow-Unrelated-Histories In GIT






Purpose







What Are Unrelated Branches?





Reproduce Error




  1. Clone the remote repository on the local machine.
  2. Delete and recreate the .git folder.
  3. Connect to the remote repository.
  4. Add a new file and commit in the local repository.
  5. 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


Picture showing the list of commands executed to reproduce the refusing to merge unrelated histories error
Click to Enlarge


How To Fix The Issue?




git pull --allow-unrelated-histories 


Picture showing pulling the data using the git pull --allow-unrelated-histories command
Click to Enlarge



Picture showing a window to enter the comments
Click to Enlarge



Picture showing the execution of git pull --allow-unrelated-histories command
Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Tuesday, June 8, 2021

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250