Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete everything and upload new version

We are using git for version control and right now we are getting a lot of warnings when trying to upload the most recent version. I am new to git and don't have patience for the restrictions, is there any way to delete everything and upload the current version?

This is what I get now when trying to upload.

$ git push origin master
Username for 'https://code.google.com':
Password for 'https://<removed>@code.google.com':
To https://code.google.com/p/<removed>/
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://code.google.com/p/<removed>/'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
like image 771
AturSams Avatar asked Jun 17 '12 12:06

AturSams


3 Answers

1.) Delete everything in your repository folder

2.) run git rm * to tell git to remove all files (check with git status whether there are any unstaged files left)

3.) do a git commit -a -m "commitmessage" a git push origin master to delete all files on the remote git server

4.) check if you have an empty remote repository now

5.) copy all new files to the local repository folder

6.) run git add * to tell git to add all new files (check with git status whether there are any unstaged files left)

7.) commit and push the new files

Now you should have the version on your remote git repository.

like image 130
Michael Kohler Avatar answered Nov 07 '22 11:11

Michael Kohler


You are unable to push because there are commit on the remote that aren't merge in to the commit that you are trying to push. If you want to discard all of the changes that are in the currently in the remote you can do something like this.

git fetch
git merge -s ours origin/master
git push origin master

Note that this throws away changes that have been introduced in the remote that you don't have in your local repository.

like image 25
CB Bailey Avatar answered Nov 07 '22 10:11

CB Bailey


If you want to permanently delete the files from the remote repository and in retrospect as if they weren't pushed in the first place to start fresh, then base on this answer you could do the following

Run the following locally (Notice the * deletes every folder/file):

git filter-branch -f --index-filter "git rm -rf --cached --ignore-unmatch *" -- --all

Now it's time to update git references locally to enforce it to forget all the history it had of those files

rm -rf .git/refs/original/

git reflog expire --expire=now --all

git gc --prune=now

git gc --aggressive --prune=now

Now push all the changes to the remote repository with a FORCE to ensure the remote repo also clears all those files

git push --all --force

This would clean up the remote repository as if no file ever existed.

like image 2
Korayem Avatar answered Nov 07 '22 09:11

Korayem