Question

I had a developer messing up the develop branch for a few weeks now without telling me and pushing the code to the remote server, I ended up after having a lot of meetings would like to replicate/clone/mirror the master branch into my development branch.

Yes I know I will be losing all the development work and that's OK right now.. I need a stable start and clear start that would be master.

So how to make my develop completely replicate/mirror my master branch?

I did the following:

git checkout develop
git reset --hard master
git commit -am "head reset"
git push

and I got the following error:

! [rejected] develop -> develop (non-fast-forward) error: failed to push some refs to 'ssh://git@xxx/project' 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.

so after getting the error I did this:

git push --force

but then if I do a pull it will pull then all the old code again... Please help me out

Was it helpful?

Solution

but then all the other programmers are going to have issues

All the other programmers will have issue anyway.

You reset develop to master (the commit shouldn't be needed here), and forced push it.

That means, any other developer will have to:

git fetch origin
git checkout develop
git reset origin/develop

And then add/merge their current change.


I do a pull it will pull then all the old code again

It should not: the develop branch and master branch should point to the same point.


The other approach would be to revert the commits of the develop branch, in order to generate a new commit which would cancel them.
The reset is the easier quicker way, but a git revert allows to not rewrite anything, and push a new commit.

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