Home > database >  Initial git push into freshly created repo on GitLab rejected
Initial git push into freshly created repo on GitLab rejected

Time:02-21

In GitLab I created a new repo from scratch (without initializing it with a README), then I ran these commands on my local machine to init and push

git init -b main
git add . && git commit -m "initial commit"
git remote add origin [email protected]:my-repo/myapp.git
git remote -v

In the next step I tried to push by git push -u origin main, but this is rejected:

! [rejected] main -> main (fetch first) error: failed to push some refs to 'gitlab.com:alexander.brehm/haraldpopp.de.git hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first integrate the remote changes hint: (e.g., 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.

According to the hints, I tried git pull, but this results in

 * [new branch]      main       -> origin/main
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.
    git pull  
If you wish to set tracking information for this branch you can do so with:
    git branch --set-upstream-to=origin/branch main

So I did a git branch --set-upstream-to=origin/main main, but this results in

hint: Pulling without specifying how to reconcile divergent branches is
hint: discouraged. You can squelch this message by running one of the following
hint: commands sometime before your next pull:
hint: 
hint:   git config pull.rebase false  # merge (the default strategy)
hint:   git config pull.rebase true   # rebase
hint:   git config pull.ff only       # fast-forward only

I don't know, what to do. I never had this issue before.

EDIT: Results of further tests:

SSH is working: ssh -T [email protected]

Status of local and remote:

$ git status
On branch main
nothing to commit, working tree clean

$ git remote show origin
* remote origin
  Fetch URL: [email protected]:my/app.git
  Push  URL: [email protected]:my/app.git
  HEAD branch: main
  Remote branch:
    main new (next fetch will store in remotes/origin)
  Local ref configured for 'git push':
    main pushes to main (local out of date)

CodePudding user response:

I couldn't figure out why the issue occured; maybe it's because when manually generating a repo in gitLab, then a file .gitlab-ci.yml is created automatically.

Finally I ended up by deleting the repo on gitLab and creating it from scratch by local command git push --all --set-upstream [email protected]:my.name/app.git In this way, everything is working.

CodePudding user response:

You should do git pull origin main then check everything in your code looks as it should and the do your git push origin main command.

  • Related