0

I want to push my commit from repository to different repository in deploy stage but I did not do it.


deploy-job:      
  stage: deploy  
  before_script:
    - 'which ssh-agent || ( apt-get update -qy && apt-get install openssh-client -qqy )'
    - eval `ssh-agent -s`
    - echo ${SSH_PRIVATE_KEY}
    - echo ${SSH_PRIVATE_KEY}
    ## Create the SSH directory and give it the right permissions
    - mkdir -p ~/.ssh
    - chmod 700 ~/.ssh
    - echo "$SSH_PUBLIC_KEY" >> ~/.ssh/id_rsa.pub
    - echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
  script:
    - git branch -a    
    - git config --global user.email "${CI_EMAIL}"
    - git config --global user.name "${CI_USERNAME}"
    - git add .  
    - git commit -m "Compiled PDF from $CI_COMMIT_SHORT_SHA [skip ci]" || echo "No changes, nothing to commit!"
    - git remote rm origin && git remote add origin http://USERNAME:${USERNAME_password}@ip:3000/USERNAME/first_exe.git
    - git branch -a
    - git push -f -u origin main

But I take this error:

To http://ip:3000/username/first_exe.git
 ! [remote rejected] main -> main (shallow update not allowed)
error: failed to push some refs to 'http://USERNAME:${USERNAME_password}@ip:3000/USERNAME/first_exe.git' 

What is the problem?

Thanks.

DrBobs
  • 76
  • 6
  • https://stackoverflow.com/a/28985327/7976758 Found in https://stackoverflow.com/search?q=%5Bgit%5D+shallow+update+not+allowed – phd Nov 15 '22 at 13:59
  • By default GitLab CI makes shallow clone and you cannot push from it to a different repository. You need to unshallow your clone. – phd Nov 15 '22 at 13:59

2 Answers2

0

GitLab allows to perform shallow cloning the repositories and you need to overcome it by doing git fetch.

Just run this before you do push.

git fetch --unshallow || git fetch --all
0

I tried it but I took this output.

$ git branch -a
* (HEAD detached from 0cd8e98)
$ git fetch --unshallow || git fetch --all
warning: no common commits
From http://10.110.10.15:3000/USERNAME/first_exe
 * [new branch]      x_branch -> origin/x_branch
 * [new branch]      main           -> origin/main
$ git push -f -u origin main
error: src refspec main does not match any.
error: failed to push some refs to 'http://USERNAME:${USERNAME_password}@ip:3000/USERNAME/first_exe.git' 
ERROR: Job failed: exit code 1
DrBobs
  • 76
  • 6
  • Can you add a commit between "fetch" and "push"? Maybe that's the problem – GChuf Nov 17 '22 at 11:15
  • I added it but it gave an error. How should I sort these commands? – DrBobs Nov 18 '22 at 08:26
  • What error? The same as before? After which command? Hard to troubleshoot without any info, unless I recreate this problem on another gitlab server ... – GChuf Nov 18 '22 at 09:03