refusing to merge unrelated histories changes

GitLab basics

Ritik
2 min readMar 11, 2022

This story is all about using GitLab. As a beginner, some of us might find it weird to set up Git on our machine and also we might be facing some unseen errors while pushing our code to Gitlab repo.

Photo by Pankaj Patel on Unsplash

1. what is GitLab?

GitLab is a place where we can manage our git repositories. It can be considered as an alternate of GitHub and Bitbucket. Currently, Gitlab is offering four versions namely Core, Starter, Premium, and Ultimate.

2. why GitLab?

A. It provides unlimited numbers of Repository both Private & Public.

B. Platform for managing repositories.

C. CI/CD for managing projects.

D. Can share Projects with anyone and control Permissions. and many more things.

3. How to setup Git.

First of all, you need to download Git and install it. after that you can run this command to check git in your machine,

git --version

4. Setup Gitlab account.

After installation of Git, I hope you have a Gitlab account if you don’t have then create one It’s a simple process. after this you need to Git with your credentials using your name and email, for that in your cmd/terminal follow these commands.

git config  --global user.name xyzgit config --global user.email “xyz@gmail.com”

alright, after these two steps you are ready to use Gitlab using your machine.

At first, you need to initialize Git using “git init” it needs to run in git bash or if you are using VS Code then use the terminal in the editor

Now next step is that you have to collect all the files at one place for that their is command ,it will collect all the files

git add .

And if you want to do this in VS Code you can do this using the Source Control option and select files in VS Code you can write a message for commit in the same section.

after this step you need to add Origin where these files need to be pushed to do so you can find a remote link in the newly created repo.then add a message and at last you need to push the files to the Branch.

git remote add origin https://gitlab.com/xyz/Test.gitgit commit -m "Message"git push origin main

these all points are for pushing code/files to the repository

sometimes you might have seen an error shown in the terminal that shows you can’t push to the branch or something about unrelated changes.

fatal: refusing to merge unrelated histories
Error redoing merge 1234deadbeef1234deadbeef

To resolve this issue you need to allow those changes using a command

git pull origin master --allow-unrelated-histories

It will fix this issues and you are ready to go…..

--

--