Reputation: 1
! [rejected] main -> main (fetch first) error: failed to push some refs to 'gitlab.com:atech4893501/sep-2024-projected-dso/cost-optimization-framework.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.
I tried these cmd but it's not work git fetch origin main:tmp git rebase tmp
Upvotes: -2
Views: 40
Reputation: 1
First I want to clarify that I created a new repo on GitLab so I was committed to pushing my local repo on the remote server(GitLab).
Here is how I solved the issue:
Stash uncommitted changes
git stash
Pull and rebase
git pull origin main --rebase
Restore stashed changes
git stash pop
If conflicts occur after stash pop:
Resolve them manually
Add the resolved files
git add.
Commit if needed
git commit -m "Merge stashed changes"
Push
git push origin main
Upvotes: 0