0

In Eclipse (using Egit) I have my repo set up like this:

I pull from a remote GitHub repo (my lecturer's) at github.com/hallvard/tdt4100-2017 I add files and modify a few of the ones I pull from there. Using Eclipse's egit, I commit changes to my local repo (including all files from the remote pull repo.), and push everything to my own GitHub repo where I then have all of my own files, and my lecturer's files, and my lecturer's modified files. That repo is at github.com/vegarab/tdt4100

Yesterday something weird happened: When pushing to my own repo., it kept saying the master branch was up-to-date, which it was NOT. YES I did stage the files, and they were commited to the local repo.

I tried going to terminal and pushing to remote from there, but no luck.

I headed to my GitHub history and found the last commit, and did a:

git reset commitid

I then tried to push to the remote, but it still said it was up-to-date? EH WHAT? I copied my local repo just to make sure I still had my files if something went wrong: I did a

git pull -f origin master

and it did some changes: My my remote repo is just a fork of the lecturer's repo. All my files are gone, except they are still there in the local repo. Trying to push them gives yet another up-to-date, except the remote now misses hunders of my own commits, and hundreds of files and folders.

What do???

vegarab
  • 309
  • 1
  • 10
  • Just to check (this may seem a bit patronising, but it's not my intention if it does)... your changes are definitely on master and not on a local branch that is yet to be merged back into master? – jonifen Feb 28 '17 at 20:45
  • I dont use branches. I just keep everything in master. Havent had any reasons to create other branches, really. – vegarab Feb 28 '17 at 20:49
  • I should add that I just went ahead and pushed my local backup repo to GitHub, and it seems to have added back ALL my commits and their history. Now I am having trouble in the original local repo becuase of conflicts I dont know how to solve. I just want to overwrite the GitHub repo with my local repo becuase it is the correct version – vegarab Feb 28 '17 at 20:53

2 Answers2

0

Make sure you are Pushing to correct repo. Say you have two remote:

upstream: The repo from where you forked your own repository
origin: Your own repository

Clone your own (origin) repo.

$ git clone <own-repo-url>

Do changes, update files, Add, Commit, Push to origin

# do some changes

$ git add .
$ git commit -m 'Add my changes'
$ git push -u origin master

Now assume upstream is updated and you need to take the upstream's new changes and then update own origin repo.

$ git pull upstream master       # pull upstream/master changes
$ git push origin master         # push the changes to origin/master  
Sajib Khan
  • 22,878
  • 9
  • 63
  • 73
  • This is what I have been doing all along. The problem is than -suddenly- one day, I was not allowed to push to origin after I had pulled changes from upstream (origin said it was up-to-date, but wasnt). I solved it with my answer below by making a copy of my local repo, and force-pushing it to origin. That way origin was updated with local changes and upstream changes. – vegarab Mar 08 '17 at 12:19
-1

I ended up pushing the local backup repo. to the remote one, which "restored" the remote one into the correct state.

I then deleted the original local repo, and created a new one, pulling from my remote repo. I then pulled new changes from lecturer and pushed to my own repo. It is now fixed.

vegarab
  • 309
  • 1
  • 10