Force a push with SourceTree

29,505

Solution 1

SourceTree is finally going to add force push: https://jira.atlassian.com/browse/SRCTREE-1156

Reason: https://answers.atlassian.com/questions/54469/how-do-i-perform-a-forced-push-push-f-from-sourcetree

Edit: It is now added in SourceTree, but you need to turn the option on in the settings.

Solution 2

In SourceTree 3 you can allow it in the advanced tab:

enter image description here

Solution 3

You can show it on Preferences -> Advanced -> Allow force push

Allow Force Push

Then force push option would be available.

Force Push Option

Solution 4

In SourceTree version 2.5.5.0 there is an option for that.

Make sure you have enabled in options:

[Menu] Tools -> Options -> [Tab] Git -> [Section] Enable Force Push

enter image description here

After that, you can force push it using push button in toolbar:

enter image description here

And it works!

Solution 5

SourceTree (as of ver. 1.4.2) issues a hg push --new-branch as needed, so if you create a new branch (as opposed to having two heads on one branch), you just do a regular push (RepositoryPush). You can, optionally, specify a branch you want to push if you have outgoing changesets on several branches.

I wasn't able to find a way to do a hg push --force proper via the SourceTree dialogs. I agree with @Ry4an that this option is more dangerous than useful. I've never done a force push since --new-branch was introduced, and never needed it to combine unrelated repositories or push a two-headed branch (a force pull is much safer).

I conclude that on a rare occasion when a force push is needed, opening Terminal won't hurt. If you disagree, please share your workflow in comments.

Share:
29,505

Related videos on Youtube

Michael Rose
Author by

Michael Rose

Working across the whole stack, using technologies that might come in handy - in my free time hacking with whatever I can find and what's interesting. Playing around with new technologies and stuff all the time.

Updated on August 05, 2022

Comments

  • Michael Rose
    Michael Rose almost 2 years

    I started using SourceTree a few days ago to manage Mercurial repositories with my Mac. Now I ran into the problem when pushing to my remote repository creates a new head on a new branch and I would like to force it.

    However, I am not able to find any specific option in SourceTree which allows me to set the force option for a push. Is it just my inability to find it or is there no possibility to set it?

    Thanks in advance Michael

    • Ry4an Brase
      Ry4an Brase over 12 years
      It's not your answers (never used sourcetree), but from the command line it's preferable to use hg push --new-branch instead of hg push --force. The reason being --force can override all sorts of "Are you sure?!" messages including (a) new head on existing branch and more importantly (b) completely unrelated repositories. Using --new-branch still stops/warns you in those other two cases.
    • Display Name
      Display Name almost 5 years
      Try Fork instead!
  • Michael Rose
    Michael Rose about 12 years
    I think the --new-branch option is enough now, since we changed the workflow a little bit (as you indirectly suggested ;). Thanks for your help!
  • Tim
    Tim almost 12 years
    I'm not sure for Mercurial, but for Git, a rebase workflow is quite common. Our entire company use SourceTree for everything, but instead of pulling/merging we instead rebase our current branch on top of the branch we wish to merge onto. Rebasing using SourceTree is all well and good, but it's useless when we can't then force push our changes up onto our remote! We then have to rip open terminal upon every "merge". Why disable dangerous features, rather than expose them with lots of warnings?
  • Helgi
    Helgi almost 12 years
    @Tim: I believe that the force push in Git differs from the force push in Mercurial. If you have to do a force push after rebase in Mercurial, you won't probably like the result (two copies of the same branch in the remote repo). As for Git, I can't say.
  • Tim
    Tim almost 12 years
    @Helgi Ah I see. Well at least they're adding it in now. I got a reply from the developer and he'll be putting it in in 1.6 :)
  • Alex Dupuy
    Alex Dupuy about 11 years
    note that this is only available in 1.6, which is just out in beta since last week: blog.sourcetreeapp.com/2013/03/28/sourcetree-for-mac-1-6-bet‌​a
  • Daniel Ryan
    Daniel Ryan about 11 years
    Are you sure it's in the first beta? I couldn't see the option and the issue in Jira still shows "in progress".
  • Alex Dupuy
    Alex Dupuy about 11 years
    Jira status shows as Closed for me, but the feature as described in the ticket indeed does not appear to be implemented (yet?) in the first beta. Hopefully in the second one? The interactive rebase (for Git) makes the beta worth downloading even without force push (at least for me).
  • Daniel Ryan
    Daniel Ryan about 11 years
    Yeah it's closed now, hopefully it's in the 2nd beta. The first beta is going well for me too :)
  • Daniel Ryan
    Daniel Ryan about 10 years
    When I said the above comment originally, I believe I missed the option in settings to turn it on. But been using force push for some time now and it is working great.
  • Gleb Kemarsky
    Gleb Kemarsky over 4 years
    In SourceTree 3.2.6 for Windows: Tools / Options / Tab "Git" / Enable Forse Push
  • Tracy Zhou
    Tracy Zhou about 3 years
    This is the correct answer for newer versions of SourceTree on Windows (my version 3.3.9).