How do I perform a forced push (push -f) from SourceTree?

Jeff Shrek May 11, 2012

Hi

I am trying to PUSH a revision after a commit and it keeps saying

abort: push creates new remote head 1a2c34f5678
(did you forget to merge? use push -f to force)"

How do I use "push -f" from SourceTree?

Thanks

15 answers

1 accepted

3 votes
Answer accepted
stevestreeting
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 11, 2012

SourceTree doesn't expose force push, because despite it being mentioned in that message from hg it's almost always *not* what you want to do.

It means that someone else has pushed before you. What you should be doing is pulling their changes, merging them (or rebasing your changes on top of them), and then pushing.

Jeff Shrek May 11, 2012

Well I am the only one using the repository so not sure what is going on ... I had to create a new repository and then move all my files over to new repo in order to continue working on my project. I could not figure out how to merge anything (even though there should have been nothing to merge) and I could not cancel the push and could not revert to an old revision. It was basically stuck and would not push to the repo and would not let me cancel the push or cancel the commit.

Crystalmyst August 6, 2012

Should this not be up to the user to do? Limiting features because they're dangerous is not helpful in any way.

Following a rebase workflow, where you always rebase and never pull/merge, you force push to update your branch when moving it on top of someone else's.
Right now, our entire company have to use the command line to do a rediculously simple command.

Can this perhaps be changed in a future release?

Like andy.bezaire likes this
stevestreeting
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 6, 2012

Hmm. My problem with it is that every time I've seen force push done, it's been a mistake. I've seen other people use tools which have an easy "Force" option that they reach for immediately without understanding the consequences, and they've deeply regretted it later. A GUI is supposed to guide you through potentially unfamiliar territory without leading you into a bear trap - that's why I've resisted having easy access to this. The way I see it is if you really understand these dangerous options, you'll find a way to do it.

A rebase workflow is fine, and should not require a force push - so long as you haven't pushed those commits before. If you have, and you then rebase them on top of someone elses branch, then anyone that pulled or fetched the commits before you rebased them now has dead lines of development.

I guess if you have a situation where no-one ever pulls anyone elses branches (in git) then this might not be such an issue, barring having lots of orphaned commits which will eventually need cleaning up. If anyone did pull, or did base their own commits on top of those which you've now rewritten, then it's a world of hurt.

It's worth noting that the default behaviour of Mercurial 2.2 is to not even allow you to rewrite changes you've pushed (via phases).

Assuming you're talking about git, what sort of setup you have to avoid the nasty consequnces of rewriting? I'm thinking that if I did allow this, I'd require people to explicitly opt-in to have it displayed on the push dialog, perhaps in Preferences with a "Yeah, I really understand what I'm doing" warning message.

Crystalmyst August 6, 2012

Good reply!

I perfectly understand that a GUI should be easy to use, and make it hard to screw things up on, but that doesn't nessecarily mean that features should be cut out. It simply means they should be difficult to access, or come with a couple of warning messages—As you say, just to make sure they really know what they're doing.

You're right with that, but although our company is only 25 people, we can frequently have people out and about, call in sick, lose their laptop, or simply want to share code, and therefore it's best to always push whenever possible. So there's a copy up on the cloud (Also handy for if you screw up your rebase and want to reset back, got a nice little ref sitting there)

You're quite right. It can be a lot of effort to maintain occasionally, but this is mostly down to communication. If you can communicate with anyone who has a local copy of your branch—Which 9/10 you do not need to do, due to it being your feature/dev branch—then you can co-ordinate the merge process, which for them is simply to delete their local ref of your branch. Simple.
Yes, clean up is also required once the repo starts to get a little too hefty. A simple archive and prune can do that for you.

It's also worth noting that git DOES allow you to rewrite history, and is one of the main reasons why it's such a powerful (yet potentionally dangerous) DVCS ;)

That sounds brilliant. If people screw things up by force pushing, then that's their fault. All you're doing is giving them the choice to force push if they really, really, really want to. Perhaps not only have a warning on setting the option to display the feature, but also a disable-able warning when selecting the force option in the push dialog, and not remember the force option of course.
That should make it sufficently difficult for anyone to accidentally force push, and only give the option to people that know what they're doing.

Do you have any more questions regarding my company's workflow?

stevestreeting
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 6, 2012

OK, that's pretty much what I thought - it does require people to know what they're doing, and does require an occasional 'cooridination dance'. If people fully understand that, it's no problem. The problem with GUIs is that they can give people a false sense of security when exposing things like this!

I still think that to support it, I'd like to make this an enableable option in preferences first rather than just always having the Force checkbox on the Push dialog with a warning behind that. The reason? People often push in a rush (maybe as they try to get out the door at the end of the day!), and this is a perfect time for rushed decisions and 'warning blindness'. I think if they got an error about creating new HEADs on the remote and the force button was right there, even with a warning they could quite happily click straight through just to get out of there even if they have absolutely no idea what it does. I think checking a box in Preferences to say "I want to see that option because I understand it" adds a little extra firewall that will make it more likely that it's only used by people that are fully aware of the consequences.

Crystalmyst August 6, 2012

You got it. But it's the workflow we've gone for, and there's quite a number of others that use this too ()

Maybe I didn't word this part right:

Perhaps not only have a warning on setting the option to display the feature, but also a disable-able warning when selecting the force option in the push dialog, and not remember the force option of course.

I meant that perhaps there should be both a setting under preferences to enable the option (as you suggested), have a disable-able ("Don't display this warning again" checkbox) warning when selecting the force option when pushing, and have it never remember the force option, so the user has to click "force" every time they want to force.
Your suggestion makes so only people who know what they're doing use it.
My first suggestion makes so people who THINK they know what they're doing, reconsider it.
My second suggestion makes so you can't blindly force push as easily.

Ultimately, it's your application. Just putting forward ideas here to help out the problem that you wish you avoid :)

stevestreeting
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 6, 2012

Gotcha, thanks for the feedback on this. I've logged this as a future improvement here: https://jira.atlassian.com/browse/SRCTREE-1156

Dave Sky July 3, 2018

Saying a force push is almost always not what I want to do is incorrect; most of the time I do a force push it is *exactly* what I meant to do...

I've been using git command-line and Git Extensions for years and have only accidentally done a force push once... and it was easily fixed because I or others have backups or there are dev/QA/production servers that have intended history.

To me it seems like it's treating the developer like an amateur to not have the option to force push when it's already available in other editors, at least as an option. The safest bet seems to be to just have an option disabled by default; having inexperienced/careless users go to command-line for this seems even less safe.

Like # people like this
33 votes
Daniel Rice June 25, 2013

+1 for adding the ability to toggle --force onto a push command in Source Treeforce. Its not the tools responsibility to prevent a user from doing something stupid, IMHO. I'm an experienced Git user and rebasing a branch that I've pushed up (usually for code review purposes) is a best practice in my book.

14 votes
Jeremy Karlsson March 8, 2016

Since Steve from Atlassian is not keen on keeping his answer up to date, I'll add this so people who google in frustration to find out how to "force push in SourceTree" (my search term in Google) can find an answer. I only got to this thread and other places who said that it was either impossible or only available on Windows. So I ended up doing it from the command line. But people are not always comfortable doing stuff in the terminal, so here's a little guide.

How to force push in SourceTree

Go to Preferences. Under general you will find a checkbox with the text "Allow force push". Check this to enable force push in SourceTree.

Now when you push, there will be a "Force push" checkbox on the bottom left of the dialog that comes up.

 

P.S.
Fuck you Atlassian for making this hard to find out by not doing your SEO right.
D.S. 

 

Best regards,

Jeremy Karlsson

Daniel Klein October 12, 2016

My version of SourceTree is 1.9.6.1, under Windows.

I found the option here:

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

Cheers!

Like # people like this
Michał Sekuła May 15, 2018

Thanks!

2.1 on Mac has this option too: Preferences -> Allow force push (at the bottom)

jordanmk May 17, 2018

Using Sourcetree 2.7.1 on macOS, it's now under Sourcetree -> Preferences -> Advanced -> Allow force push

Like # people like this
12 votes
Alex Ford March 26, 2014

Ugh, I hate it when apps decide to limit what I can do in the name of the dummies who will get themselves into a bind. Make it find to hard this option if you want, even make it flash big red text warning them what they are doing, but don't just leave it out...

This annoys me the same way Fogbugz annoyed me when they just arbitrarily decided that NOTHING can be deleted, only archived. So now we have about 25 to 30 test tickets that can't be deleted, from me trying to interface with the Fogbugz API from our application and creating test tickets.

Give your advanced users some credit. I just spent time restructuring my commits, changing things around. I reset back one commit because I didn't want it in the history. Now I go to push and of course I need to force push because the remote still has the commit I'm deliberately trying to remove. I know that I will not step on anyone's toes; I know what I'm doing. Yet now I have to drop down to the command line just to run one stupid command.

Why is it so bad to include an advanced menu with some kind of warning, but give me the option to actually do the things that git can do?? Whenever you force me to drop to the terminal I start to feel like I should just stay there. What's the point of a GUI if I still have to use the command line? I really like the GUI when it does what I expect it to; it's just when it doesn't that it falls short and puts a bad taste in my mouth.

10 votes
manusharma_repo May 9, 2018

For OS X, found this options in Preferences > Advanced > Allow Force Push

 

(May 2018, version 2.7.3 (169))

 

 

Screen Shot 2018-05-09 at 2.57.34 PM.png

clozach December 25, 2018

👍❤️🌟

Wish there was a way to seriously bump your answer's visibility without posting a whole new question!

Like # people like this
5 votes
Steven Olson July 31, 2015

For those like me who found this as the top result when trying to figure out how to do a force push:

This feature is not done in SourceTree for Windows - just SourceTree for Mac

Please vote up the ticket to show your support: https://jira.atlassian.com/browse/SRCTREEWIN-338

Dana Gatley November 1, 2018

WIndows: Tools-->Options-->Git Tab-->Enable Force Push
(Use safe push) added as well
image.png

2 votes
Carl Dunham July 15, 2016

It sure would be nice to include an option for `--force-with-lease`, for the reasons mentioned on the Atlassian blog: https://developer.atlassian.com/blog/2015/04/force-with-lease/

2 votes
Alex Ford November 21, 2013

I'd like to add my two cents. I also agree with many others about limiting features. I don't mind obfuscating some more dangerous features in some kind of an "advanced" menu or something, as long as I can get to it. This is the absolute number one reason why I HATE the official Github mac/windows client. It hides A TON of stuff, including push & pull (which is really irritating). Whenever I am forced to drop to the command line it lessens my opinion of the tool.

I know what I'm doing when I force push and I really like sourceTree. Please add the ability to do force push. I don't care if it's in blinking red text that says the world will explode if you use it, just add it please. I don't think it's atlassian's job to make sure I don't make a silly mistake; I think a clear warning message would be just fine.

I do want to give props though for creating the aboslute best cross-platform git GUI I've yet to use. I'm so glad there is a "fetch" button at the top instead of just "pull". You guys have done a stellar job of putting all of git's complicated options into a nice interface that's easy to look at. Now if we could just add in some of these things that you deliberately left out I would be a very happy customer. I'd even be a paying customer for this product if there was such an option. It's that good.

Edit: I didn't notice that this was added, my bad. I am very grateful :)

1 vote
Sean Westlake November 22, 2013

Where is the option to enable force push?

I have version 1.3.2.0 and it is up to date.

Alex Ford March 26, 2014

It's only in version 1.7.0 and higher. Sounds like you're using the version from the App store yeah? It's no longer maintained (which is a shame). Get it from the website.

Brett Gerhardi June 17, 2015

I don't get it.. latest version is 1.6.14 on that site?

Alex Ford June 17, 2015

@Brett Gerhardi The version numbers for the [Windows](http://i.imgur.com/Ze0U0Wg.png) version are different from [Mac](http://i.imgur.com/gHH7jLg.png).

Brett Gerhardi June 18, 2015

Ah thanks, any chance we will see this option in the windows version?

0 votes
ThomasGHenry May 18, 2020

For folks like me arriving late to the party from google...

Screen Shot 2020-05-18 at 17.47.26.png

0 votes
ThomasGHenry May 18, 2020

VS Code's solution seems pretty reasonable, balancing protection and convenience. 

image.png

0 votes
Jay Viper June 1, 2018

Suggestion please: can this please be done on a per repo basis. I wouldn't mind turning on this feature on repos where I'm the only developer but I would normally turn it off on an multi-dev repo.

Thanks!

0 votes
Andreas L November 11, 2013

Any news on this for git?

Or is there maybe a better way to accomplish what we are doing with force push?

We use gitflow, and before merging a working branch (feature/bugfix/hotfix) to develop or master, we do a squash rebase from the parent branch (master or develop). We squash the working branch in order not to clutter the parent branch with a lot of intermediate commits. Then we need to force push the working branch to origin, rewriting history of the working branch. Finally, the working branch is merged to the parent branch, creating a single commit for the added feature on the master branch. (Or sometimes a few commits if applicable and desired during the squash.) Working branch is then deleted.

(If we do not squash commits, it is very hard to encourage everyone to do many intermediate commits, and many commits is of cause valuable if something goes wrong, HW failure or whatever.)

Crystalmyst November 11, 2013

https://jira.atlassian.com/browse/SRCTREE-1156

This has been mered into 1.7.0, and has been there since. I'm using it now.

0 votes
MikeL August 6, 2012

SmartGit supports forced-push perfectly: It detects when it is needed and asks the user (if enabled in the preferences). No boring checkbox.

Crystalmyst August 7, 2012

Problem with this, as described in the comments above, is that if it's too easy for the user to do, they can screw up their entire repo—while the feature should be there, agreed—and then blame the GUI for throwing their repo into chaos. It's best that that situation is prevented as much as possible, while still being easy to use for those that need to, and know what they're doing.

MikeL August 7, 2012

By default the forced push is not possible, you first need to enable it in the preferences. Otherwise SmartGit will abort the push. I need forced push nearly every second day for rebased branches which only I control.

0 votes
Crystalmyst August 6, 2012

You got it. But it's the workflow we've gone for, and there's quite a number of others that use this too ()

Maybe I didn't word this part right:

Perhaps not only have a warning on setting the option to display the feature, but also a disable-able warning when selecting the force option in the push dialog, and not remember the force option of course.

I meant that perhaps there should be both a setting under preferences to enable the option (as you suggested), have a disable-able ("Don't display this warning again" checkbox) warning when selecting the force option when pushing, and have it never remember the force option, so the user has to click "force" every time they want to force.
Your suggestion makes so only people who know what they're doing use it.
My first suggestion makes so people who THINK they know what they're doing, reconsider it.
My second suggestion makes so you can't blindly force push as easily.

Ultimately, it's your application. Just putting forward ideas here to help out the problem that you wish you avoid :)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events