I have a folder running locally that contains a website. It runs on xampp on my computer quite happily. I know that has been hooked up to git in the past and I continue to add, commit and push my changes through the command line and it all works as all my other git repos do, except they update on my github dashboard online to show when they were last edited etc.
Problem is this one folder, Demo, isn’t updating the supposedly connected repo on my github dashboard.. I’ve made loads of changes and I’m committing it to somehwere but it’s not where I expected… its showing the most recent changes being over 4 months ago! Is there any way to easily reconnect the two? I dont’ mind losing whatevers in the ghost repo showing on github but I can’t lose anything on my local Demo folder. I’m happy enough on git to do the basics but if anything unexpected happens I get terrified I’m going to delete everything!
That message means that your local repo has diverged from the GitHub remote repo; that is, there are local commits that don’t exist remotely, and vice versa.
If you really don’t care what’s happened to the remote repo, then you can run
git push -fto force the push through, but if there are any other repos (yours or anyone else’s) that have already pulled the non-local changes that have somehow ended up on GitHub, then this will really screw things up for them! Any changes on GitHub that you don’t have locally will be lost.If in doubt, commit any local changes, make a note of the current HEAD commit ID (you can use
git showto find it) and then pull down the remote changes, fix any merge conflicts, and push back up. If things go wrong, you can always justgit reset --hard <commit-id>to go back to where you were before. This route doesn’t modify history, so there’s no danger of losing anything.Basically you need to be careful in Git with any operation that modifies the commit history of a repo, which
push -fdoes, since it’ll potentially lead to inconsistent histories between repos. On the other hand, if you only append to a repo’s history (which is what you should be doing, e.g. withgit commit,git pull,git merge, etc.) then if it breaks, you can always get it back into a working state just by rewinding to before the offending commits withgit reset.Also, you can see the commits on GitHub that you don’t have with
git log origin/master...master, orgit diff origin/master...masterto see the actual changes (make sure you rungit fetchfirst).