3

I am managing project of Unity (ver 4.6.3) with sourceTree I just wanted to return to the previous commit, right click to select "Reset current branch to this commit", select "Hard" in the using mode, and put it back to the previous commit. After that, I tried to push, but I failed to push. Sorry, I forgot to take the error at that time.

After that, I thought that I could not push as it was, so I created another remote repository, moved my Unity project there and committed it. Although I was able to commit, I could not push it. The error at that time is here

git -c diff.mnemonicprefix=false -c core.quotepath=false push -v --tags    
origin master:master
fatal: HttpRequestException encountered.
   ????v??????M????G???[??????????????B

Pushing to "my remote repository"
To "my remote remote repository"
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'my remote repository'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

Is there a file that needs to be deleted? If you know answer, please let me know.

古谷賢士
  • 33
  • 1
  • 5
  • `HttpRequestException` is kind of... network issue.. can you put more details on the error? *After that, I tried to push, but I failed to push. Sorry, I forgot to take the error at that time.*, you had to take note that some repository can be configured to prevent `force push`. – Bagus Tesa Aug 16 '18 at 00:32
  • also if your remote is on GitHub, [probably you want to use TLS1.2 exclusively](https://stackoverflow.com/questions/48956927/cant-push-git-visual-studio-git-failed-with-a-fatal-error-fatal-httprequest). everything is a guess though, not enough information to help.. :( – Bagus Tesa Aug 16 '18 at 00:35
  • I changed the question to display the whole error. Could you tell me the answer? And, I am using bitbucket. – 古谷賢士 Aug 16 '18 at 00:51
  • *Updates were rejected because the tip of your current branch is behind its remote counterpart.* shows that your push is not allowed. Is the new repository is forked from the old one? seems force push is not allowed. – Bagus Tesa Aug 16 '18 at 01:12

2 Answers2

3

There is following option in my Source Tree v. 3.1.2:

ToolsOptionsGitEnable Force PushUse Safe Force Push (--force-with-lease)

lu_ko
  • 4,055
  • 2
  • 26
  • 31
  • 1
    I've referenced your answer in the Atlassian SourceTree issues tracking https://jira.atlassian.com/browse/SRCTREE-4964 – bvanlew Jun 12 '20 at 07:44
1

If you do a reset --hard, you will need to force the push in order to complete your operation.

It is supported by SourceTree since 2016:

You'll first need to enable force-push in the options menu, and from there you will be able to choose between using "safe" and "unsafe" force-push.
Each time you use force-push from the push dialog you'll need to check the checkbox, and confirm the dialog prompt.

Make sure you have warned your colleague, if you are not alone working on that repository.
(considering git push --force-with-lease is not yet supported by SourceTree)

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250