Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefer --force-with-lease over --force #363

Merged
merged 1 commit into from
Oct 26, 2015
Merged

Prefer --force-with-lease over --force #363

merged 1 commit into from
Oct 26, 2015

Conversation

calleluks
Copy link
Contributor

Using --force-with-lease allows one to force push without the risk of
unintentionally overwriting someone else's work.

The git-push(1) man page states:

Usually, "git push" refuses to update a remote ref that is not an
ancestor of the local ref used to overwrite it.

This option overrides this restriction if the current value of the
remote ref is the expected value. "git push" fails otherwise.

--force-with-lease alone, without specifying the details, will protect
all remote refs that are going to be updated by requiring their
current value to be the same as the remote-tracking branch we have for
them.

@mike-burns
Copy link
Contributor

Yes!

@teoljungberg
Copy link
Contributor

I love --force-with-lease, and it fits nicely into our rebase workflow.

<sidebar> I've intended to write a blogpost about it for months. Maybe one day. </sidebar>

@seanpdoyle
Copy link
Contributor

This sounds great, but it's very verbose.

Is there an abbreviation? Is there any way to override the -f flag to do this instead?

@teoljungberg
Copy link
Contributor

There is no abbreviation according to the man page

@mike-burns
Copy link
Contributor

Nor could I find one in the codebase.

@mike-burns
Copy link
Contributor

If it's too verbose, may I recommend:

[alias]
  pf = push --force-with-lease

@seanpdoyle
Copy link
Contributor

@mike-burns is that's the case, should/could there be a matching PR to the dotfiles once if this is merged?

@mike-burns
Copy link
Contributor

@seanpdoyle no complaints from me!

seanpdoyle added a commit to thoughtbot/dotfiles that referenced this pull request Oct 16, 2015
Using `--force-with-lease` allows one to force push without the risk of
unintentionally overwriting someone else's work.

The git-push(1) man page states:

> Usually, "git push" refuses to update a remote ref that is not an
> ancestor of the local ref used to overwrite it.
>
> This option overrides this restriction if the current value of the
> remote ref is the expected value. "git push" fails otherwise.
>
> --force-with-lease alone, without specifying the details, will protect
> all remote refs that are going to be updated by requiring their
> current value to be the same as the remote-tracking branch we have for
> them.
>
> --@calleerlandsson
> -- thoughtbot/guides#363
@seanpdoyle
Copy link
Contributor

seanpdoyle added a commit to thoughtbot/dotfiles that referenced this pull request Oct 16, 2015
Using `--force-with-lease` allows one to force push without the risk of
unintentionally overwriting someone else's work.

The git-push(1) man page states:

> Usually, "git push" refuses to update a remote ref that is not an
> ancestor of the local ref used to overwrite it.
>
> This option overrides this restriction if the current value of the
> remote ref is the expected value. "git push" fails otherwise.
>
> --force-with-lease alone, without specifying the details, will protect
> all remote refs that are going to be updated by requiring their
> current value to be the same as the remote-tracking branch we have for
> them.
>
> --@calleerlandsson
> -- thoughtbot/guides#363
gabebw added a commit to gabebw/dotfiles that referenced this pull request Oct 16, 2015
> `--force-with-lease` alone, without specifying the details, will protect all
> remote refs that are going to be updated by requiring their current value to
> be the same as the remote-tracking branch we have for them.

thoughtbot/guides#363
@calleluks
Copy link
Contributor Author

I'll merge this.

Using `--force-with-lease` allows one to force push without the risk of
unintentionally overwriting someone else's work.

The git-push(1) man page states:

> Usually, "git push" refuses to update a remote ref that is not an
> ancestor of the local ref used to overwrite it.
>
> This option overrides this restriction if the current value of the
> remote ref is the expected value. "git push" fails otherwise.
>
> --force-with-lease alone, without specifying the details, will protect
> all remote refs that are going to be updated by requiring their
> current value to be the same as the remote-tracking branch we have for
> them.
@calleluks calleluks merged commit 150d2d6 into master Oct 26, 2015
@calleluks calleluks deleted the lease branch October 26, 2015 08:46
aauren pushed a commit to aauren/dotfiles that referenced this pull request Dec 21, 2015
Using `--force-with-lease` allows one to force push without the risk of
unintentionally overwriting someone else's work.

The git-push(1) man page states:

> Usually, "git push" refuses to update a remote ref that is not an
> ancestor of the local ref used to overwrite it.
>
> This option overrides this restriction if the current value of the
> remote ref is the expected value. "git push" fails otherwise.
>
> --force-with-lease alone, without specifying the details, will protect
> all remote refs that are going to be updated by requiring their
> current value to be the same as the remote-tracking branch we have for
> them.
>
> --@calleerlandsson
> -- thoughtbot/guides#363
bmorrall pushed a commit to bmorrall/dotfiles that referenced this pull request Jan 26, 2016
Using `--force-with-lease` allows one to force push without the risk of
unintentionally overwriting someone else's work.

The git-push(1) man page states:

> Usually, "git push" refuses to update a remote ref that is not an
> ancestor of the local ref used to overwrite it.
>
> This option overrides this restriction if the current value of the
> remote ref is the expected value. "git push" fails otherwise.
>
> --force-with-lease alone, without specifying the details, will protect
> all remote refs that are going to be updated by requiring their
> current value to be the same as the remote-tracking branch we have for
> them.
>
> --@calleerlandsson
> -- thoughtbot/guides#363
bmorrall pushed a commit to bmorrall/dotfiles that referenced this pull request Jan 27, 2016
Using `--force-with-lease` allows one to force push without the risk of
unintentionally overwriting someone else's work.

The git-push(1) man page states:

> Usually, "git push" refuses to update a remote ref that is not an
> ancestor of the local ref used to overwrite it.
>
> This option overrides this restriction if the current value of the
> remote ref is the expected value. "git push" fails otherwise.
>
> --force-with-lease alone, without specifying the details, will protect
> all remote refs that are going to be updated by requiring their
> current value to be the same as the remote-tracking branch we have for
> them.
>
> --@calleerlandsson
> -- thoughtbot/guides#363
bmorrall pushed a commit to bmorrall/dotfiles that referenced this pull request Jan 27, 2016
Using `--force-with-lease` allows one to force push without the risk of
unintentionally overwriting someone else's work.

The git-push(1) man page states:

> Usually, "git push" refuses to update a remote ref that is not an
> ancestor of the local ref used to overwrite it.
>
> This option overrides this restriction if the current value of the
> remote ref is the expected value. "git push" fails otherwise.
>
> --force-with-lease alone, without specifying the details, will protect
> all remote refs that are going to be updated by requiring their
> current value to be the same as the remote-tracking branch we have for
> them.
>
> --@calleerlandsson
> -- thoughtbot/guides#363
sheck pushed a commit to sheck/dotfiles that referenced this pull request Feb 15, 2016
Using `--force-with-lease` allows one to force push without the risk of
unintentionally overwriting someone else's work.

The git-push(1) man page states:

> Usually, "git push" refuses to update a remote ref that is not an
> ancestor of the local ref used to overwrite it.
>
> This option overrides this restriction if the current value of the
> remote ref is the expected value. "git push" fails otherwise.
>
> --force-with-lease alone, without specifying the details, will protect
> all remote refs that are going to be updated by requiring their
> current value to be the same as the remote-tracking branch we have for
> them.
>
> --@calleerlandsson
> -- thoughtbot/guides#363
aauren pushed a commit to aauren/dotfiles that referenced this pull request Jun 11, 2016
Using `--force-with-lease` allows one to force push without the risk of
unintentionally overwriting someone else's work.

The git-push(1) man page states:

> Usually, "git push" refuses to update a remote ref that is not an
> ancestor of the local ref used to overwrite it.
>
> This option overrides this restriction if the current value of the
> remote ref is the expected value. "git push" fails otherwise.
>
> --force-with-lease alone, without specifying the details, will protect
> all remote refs that are going to be updated by requiring their
> current value to be the same as the remote-tracking branch we have for
> them.
>
> --@calleerlandsson
> -- thoughtbot/guides#363
echopi pushed a commit to echopi/dotfiles that referenced this pull request Nov 8, 2016
Using `--force-with-lease` allows one to force push without the risk of
unintentionally overwriting someone else's work.

The git-push(1) man page states:

> Usually, "git push" refuses to update a remote ref that is not an
> ancestor of the local ref used to overwrite it.
>
> This option overrides this restriction if the current value of the
> remote ref is the expected value. "git push" fails otherwise.
>
> --force-with-lease alone, without specifying the details, will protect
> all remote refs that are going to be updated by requiring their
> current value to be the same as the remote-tracking branch we have for
> them.
>
> --@calleerlandsson
> -- thoughtbot/guides#363
aceyoung9 pushed a commit to aceyoung9/dotfiles that referenced this pull request Dec 1, 2016
Using `--force-with-lease` allows one to force push without the risk of
unintentionally overwriting someone else's work.

The git-push(1) man page states:

> Usually, "git push" refuses to update a remote ref that is not an
> ancestor of the local ref used to overwrite it.
>
> This option overrides this restriction if the current value of the
> remote ref is the expected value. "git push" fails otherwise.
>
> --force-with-lease alone, without specifying the details, will protect
> all remote refs that are going to be updated by requiring their
> current value to be the same as the remote-tracking branch we have for
> them.
>
> --@calleerlandsson
> -- thoughtbot/guides#363
moofish32 pushed a commit to moofish32/dotfiles that referenced this pull request Jan 12, 2017
Using `--force-with-lease` allows one to force push without the risk of
unintentionally overwriting someone else's work.

The git-push(1) man page states:

> Usually, "git push" refuses to update a remote ref that is not an
> ancestor of the local ref used to overwrite it.
>
> This option overrides this restriction if the current value of the
> remote ref is the expected value. "git push" fails otherwise.
>
> --force-with-lease alone, without specifying the details, will protect
> all remote refs that are going to be updated by requiring their
> current value to be the same as the remote-tracking branch we have for
> them.
>
> --@calleerlandsson
> -- thoughtbot/guides#363
@ghost
Copy link

ghost commented Jul 22, 2017

@teoljungberg wrote:

I've intended to write a blogpost about it for months. Maybe one day.

Looks like one of your colleagues has done this for you :)

bbrandt added a commit to bbrandt/salt that referenced this pull request Jun 12, 2018
Using `--force-with-lease` allows one to force push without the risk of
unintentionally overwriting someone else's work.

The git-push(1) man page states:

Usually, "git push" refuses to update a remote ref that is not an ancestor of the local ref used to overwrite it.

This option overrides this restriction if the current value of the remote ref is the expected value. "git push" fails otherwise.

Imagine that you have to rebase what you have already published. You will have to bypass the "must fast-forward" rule in order to replace the history you originally published with the rebased history. If somebody else built on top of your original history while you are rebasing, the tip of the branch at the remote may advance with her commit, and blindly pushing with --force will lose her work.

This option allows you to say that you expect the history you are updating is what you rebased and want to replace. If the remote ref still points at the commit you specified, you can be sure that no other people did anything to the ref. It is like taking a "lease" on the ref without explicitly locking it, and the remote ref is updated only if the "lease" is still valid.

References:
- https://developer.atlassian.com/blog/2015/04/force-with-lease/
- thoughtbot/guides#363
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants