0

I followed the instructions given in this SO question to move recently committed changed to a branch instead.

In short, I did the following on my local repo,

git branch newbranch
git reset --hard HEAD~3 # Go back three commits
git checkout newbranch

My remote repo (which only I access) however still has the commits in master.

I can't at present push the changes to remote because the local repo is missing some commits and it asks me to merge in changes through a pull.

How can I get the remote repo to reflect the new branch?

Community
  • 1
  • 1
Brendan
  • 18,771
  • 17
  • 83
  • 114

2 Answers2

1

Your can use the -f flag to force push to the remote repo.

git push -f

-f, --force

Usually, the command refuses to update a remote ref that is not an ancestor of the local ref used to overwrite it. This flag disables the check. This can cause the remote repository to lose commits; use it with care.

More at: git-push(1) Manual Page

Bleeding Fingers
  • 6,993
  • 7
  • 46
  • 74
1

If the remote repository you push to has been initialized properly with

git init --bare --shared

then

git push -f

will still fail because the git config file will contain

[receive]
    denyNonFastforwards = true

The commit you are trying to push is a non fast forward commit so you will need to change the behavior (at least temporarily) to allow non fast forward commits. I usually just uncomment the line above but you can do it with the official git config interface.

slobobaby
  • 696
  • 7
  • 10