Question

There is a repo on github named A. I cloned this repo to my local from github. The original repo A has a branch named 'a', which is at a previous version from A. There was a commit from the owner of the repo which deleted the history and replaced all the files on the repo. On github if you comapre the two, it says, A and a are entirely different commit histories

My problem is I want to push a commit on a which is in sync kind of was like a back up before the owner fast forwarded the master branch. But if I git pull before commit(which is a good practise) I am sure to run into problems since it's not at all into sync.

The best solution would be to stop tracking what master does and replace it with the a branch which is not possible as to what I know. What should I do to delete the fast-forward commit and make it sync back to 'a' branch.

P.S. The owner of the repo gets ![rejected] master -> master (non-fast-forward) it he tries to do a git pull. Says "the tip of his currrent branch is behind its remote counterpart"

If any of the part is unclear please feel free to ask, I am running into this problem since continuous 2days! Thanks.

Was it helpful?

Solution 2

I solved it with a simple solution. 1. The local changes were committed with
git commit -a -m 'temp'.
2. I made a new branch with all those changes reflecting in my local machine.
3. Did a checkout on master branch.
git checkout master
4. Did a force push after committing on my original repo.
git push -f upstream master
Now my local and original repo are completey in sync. P.S. There is a lot of warning given on force push since it changes the history. So use it very carefully.

OTHER TIPS

(If you had a question hidden somewhere, I sure couldn't find it. Here's my answer based on guessing what you tried to ask:)

I'm not sure why you think that doing blind git pull is a good practice before committing stuff. Doing a git fetch followed by gitk master origin/master sure makes sense to get a sense of the current status. Then you usually want to decide between git checkout master && git rebase origin/master and git checkout master && git merge origin/master.

If your local master branch is somewhere it should not be, first make sure that you do not have uncommitted changes and then do git checkout master && git reset --hard [sha1-of-the-commit-you-want] to move the master branch anywhere you like. If you then want to overwrite the master branch on the origin with your new correct state, just do git push -f origin master. Note that if other people have checked old master from origin, the will need to rebase all their commits to follow your new master. See https://www.kernel.org/pub/software/scm/git/docs/git-rebase.html#_recovering_from_upstream_rebase for details.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top