KansaiRobot
KansaiRobot

Reputation: 9912

gitlab and its "a default branch does not exist" caused problems

I created a repository in gitlab and discovered that my developers can not initiate this repo. (Googling it shows that it seems to be an unresolved bug) with the error message being

A default branch (master) does not yet exist
Ask a project Owner to create a default branch

So I had a branch new repo and the developer could not upload its code. So I did the following:

  1. I created a default README and the repo got a master branch
  2. In my developer PC, we did git fetch origin master

So now, master and origin/master was in two different places

I tried git merger origin/master but I got fatal: refusing to merge unrelated histories

I guess because all the work was in the developer's master and the origin/master was almost empty (except the README)

So I did

  1. git checkout -b newBranch
  2. git rebase origin/master

And now I have the whole development over origin/master so I can do

git push origin newBranch

and the developer's work is uploaded to the repo

However there are two things that are worrying me:

  1. When I do git log the newBranch branch is over origin/master but there is no master anywhere. When I do it with show all, the master appears below origin/master and the supposedly rebased commits are actually copied. Why master does not appear in git log is unknown to me
  2. How I can solve this mess? Ideally I would like the developer to have also a master branch that reflects what it is in the repo. Right now he is working only from newBranch

Upvotes: 4

Views: 8676

Answers (1)

torek
torek

Reputation: 488083

An empty repository, such as the one you created here, never has any branches.

This is not an error but it makes the repository useless. To correct the problem, you must put at least one commit into the repository. The existence of the first ever commit allows you to create as many branch names as you like. One of those branch names can then be the default branch. You may choose any name you like for the default branch, but in order to create any branch names, you must have at least one commit.

That's really all there is to it. This is why "create new repository" operations on many web hosting sites offer to create the first commit for you as well.

(Now that you have an origin/master in your local repository, you can git switch master to create a local master too, if you want. But there's no reason you must have a local master branch name. The point of having a branch name is to help you find commits, and to help you as you add new commits to that branch: you create a name if you want to find a specific commit and/or add commits there.)

Upvotes: 3

Related Questions