Reputation: 321
i am using GitLab to store my code, at first, i pushed it on the branch master and nothing unexpectedly happened, then i think it would be my last commit for my project and then i deleted my whole project in my desktop.
Then i have idea to improve the last project that i have just completely deleted previously.
Then, i create a new project do some git syntax to merge my current project to git repository of the project that i deleted
feel so regret for this stupid thing that i have made :(
firstly, i initialized git:
git init
then, just want to make sure there are no branch-name, so i type:
git remote -v
of course, it clears, so i added my previous master branch-name git ssh "[email protected]:Khangithub/react-practical-1.git" and it is called "origin"
git remote add origin [email protected]:Khangithub/react-practical-1.git
git add .
git commit -m "commit massage"
git push -u origin master
and it returns this error to me:
To https://gitlab.com/Khangithub/react-practical-1.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://gitlab.com/Khangithub/react-practical-1.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Enumerating objects: 42, done.
Counting objects: 100% (42/42), done.
Delta compression using up to 8 threads
Compressing objects: 100% (38/38), done.
Writing objects: 100% (42/42), 221.29 KiB | 7.14 MiB/s, done.
Total 42 (delta 5), reused 0 (delta 0), pack-reused 0
remote: GitLab: You are not allowed to force push code to a protected branch on this project.
To https://gitlab.com/Khangithub/react-practical-1.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://gitlab.com/Khangithub/react-practical-1.git'
it asks me to git pull, so i tried:
git pull
then
git pull -u origin master
even
git pull -f origin master
even though i don't understand what i mean but i guess it want me to create a new branch in the git repository but i want to merge all my current project with code that i have pushed on from the project that i deleted :(
I don't want to create a brand new gitLab project with the same purpose with one already had, thank you for taking time to help me out, it means a lot to me, hope you have a good day, thank you so much
Upvotes: 1
Views: 6277
Reputation: 3509
The problem your are having seems to be caused by the fact that you created a second local repository with git init
instead of cloning the one you already have from gitlab. This creates a problem when pushing, because you now try to push changes from your local repository that shares no common history with the remote repository and gitlab is protecting you from overwriting all history in the remote repository that exists on gitlab.
To get your project on gitlab updated with your current changes try the following:
git clone https://gitlab.com/Khangithub/react-practical-1.git yourLocalFolder
yourLocalFolder
that you just cloned from gitlab.This makes sure that there is a shared history between your local repository and your remote repository before pushing.
Upvotes: 3