I am fairly new to github as a whole, so there are some explaination or words that are not quite clear, I am sorry.
I used to have a folder called "statictis" that is link with a github repo called "statictis code files". The original folder which contains the original files that is linked to the original github is now gone on my local machine.
Recently, I have created some code files that are related to the "statictis code files" repo that I have on github, but because I don't have the original folder that is linked to the repo (I deleted it). I am trying to find a way to push my new code to the old repo but because the original folder that is linked to the repo is now gone, I am stuck, I tried to add it the usual way:
git init
git remote add origin <remote link>
git add .
git commit -m 'New edit date/time'
git push origin master
And I received this error:
! [rejected] master -> master (fetch first)
error: failed to push some refs to '*github repo link*'
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.
And I have tried to pull by using the pull command:
git pull <remote> master:dev
git push origin master
But I receive a new error saying that my brach was behind. So I saw a suggestion saying using push -f, but this will delete my commit.
If you have any suggestion mention. Instruction would be much appreciate.
TL;DR:
-The folder that is linked to my github repo on my local machine is now deleted.
-I have some files in a totally different new folder that are related to the subject of the repo and I am trying to push it to the old github repo but it keep displaying errors.
CodePudding user response:
So you created a repo and accidentally lost the files in your local or in github? If you've lost the files on your local, you could just clone the project again from the repo to your local.
git clone https://github.com/github/training-kit.git
Alternately, if some of your changes in your local is present and you only deleted a couple of folders, you could revert the changes you made.
git checkout .
or git restore .
will revert all your local uncommitted changes.
Then make changes code_2 and push it back to the repo. Let me know if this understanding is correct or modify your question and I can update my answer too :)