2

I just set up a new gitlab group and a fresh private gitlab repo in that group. I am attempting to create a project from an existing folder.

The problem

I deleted the .git folder containing all of the git history from the existing folder. Then I created the gitlab repository, executed

git init
git remote add origin git@gitlab.com:my_group_username/my-repo.git
git add .
git commit -m "initial commit"
git push origin master

I got this error:

 ! [remote rejected] master -> master (pre-receive hook declined)

What I have tried

  • I checked to make sure the master branch isn't protected. It's not.
  • I checked to see what webhooks are configured. There are none.
  • I tried pushing to a new branch, not named master
  • I checked my user configuration with
git config list

and my user info is configured as expected.

  • I deleted the repo, recreated it, and tried to push. Same issue.
  • I checked to make sure that my gitlab user is configured as a contributor. I am the owner of the project.
  • I even created a Github repo in the same way, and was able to push my commits to that repo without any issues.

Any ideas what might be causing this error?

Edit - git push command and output:

git push -u origin --all
Enumerating objects: 31, done.
Counting objects: 100% (31/31), done.
Delta compression using up to 12 threads
Compressing objects: 100% (24/24), done.
Writing objects: 100% (31/31), 78.73 KiB | 8.75 MiB/s, done.
Total 31 (delta 0), reused 0 (delta 0)
remote: GitLab: LFS objects are missing. Ensure LFS is properly set up or try a manual "git lfs push --all".
To gitlab.com:dellacortelab/prospr.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git@gitlab.com:dellacortelab/prospr.git'

Looking at this again, it looks like there is an issue with LFS (large file storage), but the repository is only 1.5 Mb in size. It originally did have some large files, but I deleted them before deleting the .git folder, so I don't know how gitlab would know about them.

Update:

There was a reference to LFS files in my .gitattributes file, so I deleted the .gitattributes file and the directory that it referenced, but I still got the same error.

Removed .gitattributes file:

potts/plmDCA_asymmetric/plmDCA_asymmetric.ctf filter=lfs diff=lfs merge=lfs -text
Jacob Stern
  • 3,758
  • 3
  • 32
  • 54
  • 2
    You say gitlab in the text and title, but github in your remote url. Which is it? – jthill Nov 11 '20 at 05:43
  • Were the fresh new repos created with README or LICENSE or `.gitignore`? – phd Nov 11 '20 at 05:55
  • 1
    Is the remote repository completely empty without any existing branch like `master` or `main`? – ElpieKay Nov 11 '20 at 06:08
  • 1
    Please show the entire output from `git push` – phd Nov 11 '20 at 06:33
  • It is gitlab - the url I posted was copied from my later experiment where I added a github repo to see if I could push to github (I could). I corrected the question to have the correct url. – Jacob Stern Nov 11 '20 at 15:04
  • The fresh gitlab repo was not created with a README or license. The github repo did have a license. – Jacob Stern Nov 11 '20 at 15:05
  • I didn't explicitly create a main or master branch, but I'm not sure how to verify that they exist - there is no drop-down menu with the names of the branches in a fresh gitlab repo. – Jacob Stern Nov 11 '20 at 15:08
  • If you want to overwrite the history, you could try a force push (add `-f` to the `push` command) – dan1st Nov 11 '20 at 15:33
  • I just tried force pushing - same error. – Jacob Stern Nov 11 '20 at 15:37

2 Answers2

0

You have deleted the .git folder. So, apparently the working copy was obtained from another repository. The problem seems to be that not all of the files tracked by git lfs were actually downloaded. By deleting the .git folder, you have lost all that information.

What you should have done instead:

While the previous repository is still setup as remote origin, ensure that all files tracked by lfs are downloaded by issuing the command

git lfs fetch --all

See this answer.

Only then switch to the new repo. I would suggest not deleting the .git folder, but adding it as another remote, say

git remote add gitlab git@gitlab.com:my_group_username/my-repo.git

The procedure described in the answer cited above pushes the files tracked by lfs explicitely with

git lfs push --all gitlab

In my case, this was not necessary. Once all files tracked by lfs have been fetched, a simple

git push gitlab master

should do the job. However, this replicates the entire history to the new repo and this is not what you want. If you want to get rid of the history, you can squash the history to one single commit. See this question on how to do this.

Adrian W
  • 4,563
  • 11
  • 38
  • 52
-1

The final solution: purging all references to LFS files from git history

  • I removed the .gitattributes file as well as the file that it referenced: potts/plmDCA_asymmetric/plmDCA_asymmetric.ctf, and commited again.
  • Still couldn't push
  • So I removed the .git directory, reinitialized the git repository, and pushed.
  • It worked!

There are probably more nuanced ways to purge the git history of referenced to LFS, but this worked.

Jacob Stern
  • 3,758
  • 3
  • 32
  • 54