Git Push failing due to missing files - eclipse

I just came across a known error with Eclipse/Glassfish in a project I am working on. Basically, Eclipse/Glassfish are somehow getting confused, and refuses to launch my Web Application. A full re-install of eclipse and glassfish still gives me the same problem when I use my project files from the github repository.
So I had to delete the repository locally, and then create a new Eclipse project with all the same code files in it. Now Eclipse/Glassfish runs the new project smoothly, and I want to update the remote repository with the new project.
However, when I do the command in git bash:
git push origin master
I get the following error:
error: failed to push some refs to 'git#github.com:......"
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.
So basically this is telling me to do a pull before i do the push. But I really don't want to do a pull, as it contains some eclipse stuff that is causing the problem that I spent hours trying to fix.
What command do I need to do, that will push the current files I have to the remote repository, and at the same time, get rid of those that don't exist locally from the remote repository? I don't mind so much if they exist in previous commits, but just not from the current one onwards....
All help much appreciated.

You can by your own risk force the push.
git push origin master --force
You will overwrite the files on origin.
...This flag disables these checks, and can cause the remote repository
to lose commits; use it with care.
Documentation:
git-push

Related

EGIT Can't connect to any repository - Missing unknown

I just created a new repository on GitHub and trying to initially push my local Java project.
I added the ssh key in my GitHub account, and it's referenced correctly by Eclipse, I assume.
I only get this error message when I'm trying to push:
Can't connect to any repository:
git#github.com:MaximStein/MyProject.git
(git#github.com:MaximStein/MyProject.git: Missing unknown
366362as232d670123a2267b4879bbd01d142426)
Any ideas?
Your Git repository seems to be broken or at least in an invalid state.
The root cause seems to be Missing unknown 366362as232d670123a2267b4879bbd01d142426 which means something (probably the HEAD) points to the object with the hash 366362as232d670123a2267b4879bbd01d142426 (which will be stored in the file .git/objects/36/6362as232d670123a2267b4879bbd01d142426) that does not exist.
In the Git History you might right-click the last commit and choose Reset > Soft (HEAD Only). If commits are missing, you might be able to recover them via the Git Reflog view.
Make also sure your Eclipse and EGit/JGit is up to date (for instance, there was an issue causing a Missing unknown error that has been fixed more than four years ago) and that you do a refresh (F5) in Eclipse after you have executed Git operations on the command line.
Try first if the push would succeed from command line (which means you need in to install Git first):
check you are correctly identified with ssh -Tv git#github.com
check your remote origin URL: git remote -v
check your local status (git status: to make sure you are on a branch, here I assume main, and that you have made at least one commit)
check your initial push: git push -u origin main
Check also if you have declared any submodules (.gitmodules file), or look for any nested Git repository (.git subfolder anywhere beside your repository root folder)
It is helpful to rule out (or not) a git-core issue, before investigation an Egit/JGit one.
And the OP Maxim confirms in the comments:
It's a good idea to try it in the command line first.
It says "fatal: bad object HEAD" when I do git status.
I think I've only made one local commit for that project.
Indeed, making local commits, in a branch, is a prerequisite to pushing anything.
In your case, do a git branch -avv to check if there are any.
If you already pushed that missing commit, assuming your main branch is main (not master):
git fetch origin
git reset --soft origin/main

Can't to push commits from local branch to github repository

I was committing and pushing in ordinary for my repository.
but once i used command of git checkout for change to the previous version of my repository.
after that i tried to commit and push, then it can not completed.
i try to use the --no-verify command to push the commit but it also not success.
error: failed to push some refs to 'https://github.com/ruwanliyanage123/Hair-4-U-Hospital.git'
i want to push my commit into github repository
Since you switched to a previous version of your repository, your head is most probably detached. You can't just go back anywhere in your history and make commits.
Consider making a branch from there and then commit to it.
Try to first check in which branch you are working do git branch, check is the one you are working. Then I sometimes do git pull to just make sure that the connection is working this should not delete your progress the you should be able to do git push. If you are afraid youll mess up first do a local back up of all project files except for the .git one which are hidden by default in windows.Lastly I would suggest never posting the actual link to your github repository in case whatever you are working is important, you can just replace with
https://github.com/user/projectname.git

What should I do when my local branch is at merging state after I pull the remote master?

I am an Android developer, and now I am doing a lot of changes locally and are trying to synchronize the local and github side of the code after I pull the merge to merge successfully and merge the code locally and run successfully.
But when I want to push always show the picture shown in the picture, push rejected. I am very puzzled, the left side of the figure is the local change, since I was a novice, no previous to ignore the file, so a series of build files, .idea files have been submitted to see the error is to show that these files are not merged.
Now I am very puzzled, how can I solve this situation, how can I submit the local code to my github library, who can help me? Many thanks!
Screenshot:
You have commits in the remote version of master that you're pushing to that are not in your local version, and vice versa. Since Git can't resolve this diversion automatically, you can't push your local version to your remote.
You may have to git pull, or if that doesn't work, git rebase, to get your branches to line up in a way that they can be merged.

GIT Removing FETCH refs from remote tracking

I am new to using GIT in eclipse i have been playing around with the tool and i did several push and merges to the server however i am seeing in the Remote Tracking option when i do a fetch i am getting branches i do not need or use anymore. How can i remove from Remote Tracking, branches i do not need anymore.
I attempted a delete however when i do a fetch again from the server they all come back. I also need these branch names however i cannot reuse them since they already exist. Under is a screen shot of what i see when i attempt to configure the FETCH option.
GIT FETCH CONFIGURATION
You need to delete those branches on the server as well as locally:
git push --delete origin <branchName>
(As in "How do I delete a Git branch both locally and remotely?")
If you don't, the next fetch will bring those branches back.
You can specify the default refspecs to fetch from a remote:
git config remote.origin.fetch +refs/heads/master:refs/remotes/origin/master
(likewise with remote.origin.push). Then delete the unwanted branches locally and fetch won't reload them unless you specifically ask.

Stopped Using Git - Now Want to Start Again. How to Get Synced Back Up?

We had a number of developers working on a large website project using Git. We have a GitHub repository and then we have the website on the server, plus all the developers have their local versions.
When we finally launched the project, I got lazy (hangs head in shame) and started making changes directly to the server, without pushing them back to the Github repo. However, other people made changes to the repo, for reasons I don't quite understand, that were never pushed down to the server and are now either outdated or wrong. We have been doing this for almost seven months.
Now the server and repo are hopelessly out of sync. I would now like to get the most updated version of the site (which is the server) back up to the Git repository so we can begin another round of development. I basically want to start with a fresh copy of what is on the server.
How would you recommend I proceed? That was the first time I had used Git. It didn't seem like such a big deal at the time but now seems like it is harder to start up again than I thought.
I have looked for instructions and don't really see anything that fits. Because I am not super confident in my Git skills, I am afraid to just start trying the few ideas I did find and losing what I have on the server.
(I know I could restore from a backup if I really messed it up but would prefer not to do that as it would take the site down.)
Can I uninstall git and start again with a fresh repo? Or is there a safe way to push the current version up to the repo?
Thanks for your help.
UPDATE: I found this answer elsewhere (Replace GitHub repo while preserving issues, wiki, etc) but I am not sure how to do this:
cd into "new" repository
git remote add origin git#github.com:myusername/myrepository (replacing myusername & myrepository accordingly)
git push --force origin master
Possibly delete other remote branches and push new ones.
Not sure what they mean by "new repository"
Make a new branch and push it to GH.
Make a new branch based on the previous
branch.
Switch to the new branch (created on #2).
Delete all the files and folders on this branch repository
except the .git folder and contains
(maintain the README.md,
.gitignore and other files if you want it).
Copy all the files from the server except
.git folder.
Commit.
Switch to local Master (created on #1)
Merge this new branch with the previous one.
Solve conflicts
(I use SmartGITthat have a visual conflict solver and helps me a lot, but you can use gitdiffif you don't want a visual interface)
Commit
Push it to GH.
I hope this helps
I figured this out. What I did was:
Make a new branch on Github to effectively store a backup.
$ git add . to stage all changes
$ git commit -m "Commit message" to commit changes
$ git push --force origin master to force changes from server to remote branch master
Once I did this, there were still hundreds of files I had deleted on the server that were not reflected on the remote github.com repository. I used the following:
$ git rm $(git ls-files --deleted)
See Removing multiple files from a Git repo that have already been deleted from disk
Then repeated git commit and git push. Now my github repo matches my server exactly.
I have not yet deleted the "backup" branch I created on github but I will.
Hope that helps someone.