Is there a force push option in GitHub Desktop?
Asked Answered
R

8

31

Using version 1.0.4, I can't find any force push option. Is command line the only way to use force?

Can't push and Can't pull

Redwing answered 21/10, 2017 at 17:27 Comment(2)
That option might be available now: see my edited answer below.Tundra
With the latest GH Desktop 3.1.5 (Jan. 2023), the new Repository menu includes a force push entry. See my revised answer below.Tundra
K
-19

Yes you can do

git push origin <your_branch_name> --force

Update!

This option worked hence accepted answer but no longer works in later versions of Git.

Khanate answered 21/10, 2017 at 17:35 Comment(5)
I’m not 100% sure, you could try with sourcetree. Maybe with git bash my command will work in that.Khanate
Thanks, I did it with Sourcetree. It's just annoying to be required to use third party software to do something the developers should have included.Redwing
Did you use terminal for git push origin --force?Jacindajacinta
Yes you use terminal, this has been deprecated, and probably for the best.Khanate
How is this related to the original question? Moderators should take it out as it is misleading. I came here trying to solve a GitHub Desktop issue as stated in the original question; only to find an answer being a CLI Git command that I already know about.Middlebrooks
T
14

Update Jan. 2023:

GitHub Desktop improves force pushing and fetching along with many great open source contributions (Jan. 2023)

GitHub Desktop 3.1.5 improves support for force pushing and fetching through the newly added Repository menu items as well as supporting pull request notifications on forks.

Previously, a user could only force push after an action such as rebasing.

Now, when users find their branch in any diverged state, they can opt to use the force push Repository menu item.

For example, a user can force push when commits exist on the remote that they are sure they want to overwrite.

https://static.mcmap.net/file/mcmap/ZG-AbGLDKwfpLC21bC2jaRA/user-images.githubusercontent.com/75402236/214120118-2d76588c-770e-4736-928e-b4252e2c601d.png?ssl=1 -- ALT GitHub Desktop repository in a diverged state with Repository menu open showing force push menu item

Similarly, a user may find themselves in a new local branch they are not ready to publish, yet they want to fetch to see if there are any new changes on their main branch they would want to merge in.
Instead of having to switch branches, they can use the Repository menu item to fetch those changes.

Learn more about GitHub Desktop here.


As of Nov. 2018, still no native support for a push --force in GitHub Desktop:

That might change, considering GitHub is now displaying who did a push --force on GitHub.

Update August 2020, issue 3580 mentioned above now include this screenshot, by turtlemaster19:

Interestingly, in the Advanced preferences of GitHub Desktop (at least on Mac) there is this interesting checkbox:

https://static.mcmap.net/file/mcmap/ZG-AbGLDKwf0bRywKVltWVclbw2nZ7-ocVI0bRywWRfQcFyQcC2jaRA/46784000/89301809-b19ec200-d62f-11ea-902b-1d4fd1663853.png

Tundra answered 16/11, 2018 at 19:8 Comment(0)
Q
13

There is a workaround to do a forced push on Github Desktop (Tested on Github Desktop for Mac, and for Windows)

STEP-1: Switch to history, tab.

enter image description here

STEP-2: Then click and drag one commit over the other. Squash commit popup will come, choose accordingly.

https://static.mcmap.net/file/mcmap/ZG-AbGLDKwf0bRywKVltWVclbw2nZ7-ocVI0bRywWRfQcFyQcC2jaRA/19490960/160462212-b9b2fd47-67d7-4796-8ea5-6dbe482536b0.png

STEP-3: Now you will be able to see force push

enter image description here

Hope this helps, Happy Coding!

Quacksalver answered 28/3, 2022 at 18:29 Comment(1)
This actually worked. I'd been using force push with GD for some time but for some reason this time the button there only showed "Pull from origin" which would mess things up, and what I really wanted to do was force push my branch. Making another empty commit, then moving that before my latest commit somehow made that button change into "Force push origin" just like you suggested in this answer. 👍🏻👍🏻👍🏻Crystallography
E
11

Update 2024: the "Repository" menu now has a "Force Push" menu item.


One workaround for the lack of a "Force Push" menu item is to right-click the latest commit in the History tab, choose "Amend Commit…", then edit the commit message.

Repeat the edit to change the commit message back again, if you like.

The "Push origin" button should have changed to "Force push origin".

Exponential answered 31/8, 2022 at 21:12 Comment(0)
W
5

If you only need to force-push just once, and are familiar with the command line, you could do this:

  1. Open the Github Desktop logs via "Help" > "Show Logs in Finder"

  2. Now perform a Push in Github Desktop

  3. You'll see what command the app is trying to perform in the logs window, e.g.:

    [ui] Executing push: git -c credential.helper= -c protocol.version=2 push origin main:main --progress (took 1.441s)

  4. Copy that call to the 'git' CLI and add a --force parameter

  5. Open a Terminal window and navigate to the folder of your local repository

  6. Perform the copied git command, and when asked for credentials, use the Github credentials you've used to login on the website

Waterage answered 21/11, 2020 at 21:24 Comment(1)
If you're getting "remote: Support for password authentication was removed on August 13, 2021" then create access token, check "public_repo Access public repositories" in token "Select scopes" and use the token instead of your password when prompted.Wop
P
2

GitHub Desktop's 'Amend Commit...' feature supports 'Force push origin'.

'Amend Commit...' option in GitHub Desktop context menu 'Amend Will Require Force Push' dialog in GitHub Desktop 'Amend last commit' button is shown in GitHub Desktop 'Force push origin' button is shown in GitHub Desktop

Payday answered 24/10, 2022 at 2:13 Comment(0)
W
1

Ran into this same issue, was able to "force" push the changes I made by using the 'upload files' feature on github. Didn't sync my local repo, but it at least got the files in the repo for me to use on another machine. Not the ideal solution I'm sure, but it worked for my purposes, in case it can help someone else.

enter image description here

Wessex answered 19/1, 2019 at 20:44 Comment(0)
O
1

GitHub Desktop actually have a force push feature. When you click "History" on Repository page, you can drag a one commit before another one which will cause force push to repository. There is no feature that you have requested at all, but it seems application is on a good way to have such thing.

Outport answered 21/2, 2022 at 19:49 Comment(0)
K
-19

Yes you can do

git push origin <your_branch_name> --force

Update!

This option worked hence accepted answer but no longer works in later versions of Git.

Khanate answered 21/10, 2017 at 17:35 Comment(5)
I’m not 100% sure, you could try with sourcetree. Maybe with git bash my command will work in that.Khanate
Thanks, I did it with Sourcetree. It's just annoying to be required to use third party software to do something the developers should have included.Redwing
Did you use terminal for git push origin --force?Jacindajacinta
Yes you use terminal, this has been deprecated, and probably for the best.Khanate
How is this related to the original question? Moderators should take it out as it is misleading. I came here trying to solve a GitHub Desktop issue as stated in the original question; only to find an answer being a CLI Git command that I already know about.Middlebrooks

© 2022 - 2024 — McMap. All rights reserved.