git-plus icon indicating copy to clipboard operation
git-plus copied to clipboard

[REQUEST] git push --force

Open bichotll opened this issue 8 years ago • 6 comments

We usually use git commit --amend, which we have to make a git push force. That's something quite common. I think that should be used quite often and I actually see the need.

bichotll avatar Jan 03 '17 11:01 bichotll

You can use the custom commands feature to get this. You can read more about it here

akonwi avatar Jan 03 '17 16:01 akonwi

Good. What I meant thought is that it should be available by default heh

bichotll avatar Jan 17 '17 11:01 bichotll

👍 for making it an easy accessible default. 200+ people at our company use this workflow of amending/rebasing and force pushing.

For what it's worth i use this alias from the command line to be explicit that i push the current branch name to a remote branch with the same name:

alias forcepush='git push --force-with-lease origin $(git_branch_name):$(git_branch_name)'

Soleone avatar Apr 19 '17 21:04 Soleone

@akonwi Are you against implementing this? My argument would be that since you did implement commit amending which is often followed by a force push - it would be a useful feature.

I couldn't get the custom command to work :[

I made sure that "Custom Commands" was checked

The following is my full ~/.atom/init.coffee:

# initialization file (not found)

atom.packages.onDidActivateInitialPackages (p) ->
if gitPlus = atom.packages.getActivePackage('git-plus')?.mainModule.provideService()
  gitPlus.registerCommand 'atom-text-editor', 'custom-git-commands:undo-last-commit', ->
    gitPlus.getRepo()
    .then (repo) ->
      gitPlus.run(repo, 'reset HEAD~1')

atom.packages.onDidActivateInitialPackages (p) ->
if gitPlus = atom.packages.getActivePackage('git-plus')?.mainModule.provideService()
  gitPlus.registerCommand 'atom-text-editor', 'custom-git-commands:push-force', ->
    gitPlus.getRepo()
    .then (repo) ->
      gitPlus.run(repo, 'push --force-with-lease')

xenithorb avatar May 11 '17 06:05 xenithorb

@xenithorb Amending a commit is less destructive than force pushing. It's a useful feature with some and a dangerous feature for others. I also force push and I do it via the run command to enforce me to be intentional.

If force pushing was to be implemented in this package, it should be behind a configuration option so users have the chance to opt-in. I'll try to do this soon but if someone else wants to create a pull request, please be my guest.

@xenithorb As far as your init script, you don't need two onDidActivateInitialPackages calls. You can do everything in one block like so

atom.packages.onDidActivateInitialPackages (p) ->
  if gitPlus = atom.packages.getActivePackage('git-plus')?.mainModule.provideService()
    gitPlus.registerCommand 'atom-text-editor', 'custom-git-commands:undo-last-commit', ->
    gitPlus.getRepo()
    .then (repo) ->
      gitPlus.run(repo, 'reset HEAD~1')

    gitPlus.registerCommand 'atom-text-editor', 'custom-git-commands:push-force', ->
    gitPlus.getRepo()
    .then (repo) ->
      gitPlus.run(repo, 'push --force-with-lease')

akonwi avatar May 12 '17 18:05 akonwi

Making this an opt-in feature makes sense to me. 👍 You should know what you're doing before you use it, but it's a workflow that 200+ devs in my company have adopted to keep a nice clean history that is as "flat" as possible.

Soleone avatar May 15 '17 21:05 Soleone