Force a push with SourceTree
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:
Solution 3
You can show it on Preferences -> Advanced -> Allow force push
Then force push option would be available.
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
After that, you can force push it using push button in toolbar:
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 (Repository → Push). 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.
Related videos on Youtube
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, 2022Comments
-
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 over 12 yearsIt's not your answers (never used sourcetree), but from the command line it's preferable to use
hg push --new-branch
instead ofhg 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 almost 5 yearsTry Fork instead!
-
-
Michael Rose about 12 yearsI 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 almost 12 yearsI'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 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 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 about 11 yearsnote 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-beta
-
Daniel Ryan about 11 yearsAre 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 about 11 yearsJira 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 about 11 yearsYeah it's closed now, hopefully it's in the 2nd beta. The first beta is going well for me too :)
-
Daniel Ryan about 10 yearsWhen 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 over 4 yearsIn SourceTree 3.2.6 for Windows:
Tools / Options / Tab "Git" / Enable Forse Push
-
Tracy Zhou about 3 yearsThis is the correct answer for newer versions of SourceTree on Windows (my version 3.3.9).