4 ms·
> ... `goops file`, it adds the file, amends the last commits and force pushes the branch Note that you should only ever do this if you are absolutely sure tha
by vog 10y ago
> ... `goops file`, it adds the file, amends the last commits and force pushes the branch
Note that you should only ever do this if you are absolutely sure that you are the only person pushing to that branch.
You should consider using "--force-with-lease" instead of "--force". Otherwise you'll sooner or later overwrite a coworker's push without a trace. Maybe they'll notice know Git good enough to fix this, but it would still be very, very annoying.
EDIT: Changed "repository" to "branch", mention "--force-with-lease".
- K0nserv 10y agoDefinitely, don't force push unless you know what you are doing and the implications of force pushing. On the other hand don't blindly listen to people who tell you that force pushing is bad and should always be avoided
- meestaahjoshee 10y agoYou can use --force-with-lease
- vog 10y agoThanks for the hint. I wasn't aware of that option.
- 0x0 10y agopush --force-with-lease can mitigate accidental overwrites though
- vog 10y agoThanks for the hint. I wasn't aware of that option.
- acobster 10y ago> Note that you should only ever do this if you are absolutely sure that you are the only person pushing to that repository. I would revise this to say the only person pushing to that branch. But yeah.
- pjc50 10y agoyou'll sooner or later overwrite a coworker's push without a trace This is the kind of thing that makes it hard to see why git has become the One True DVCS - you can not just overwrite history but actually lose other people's work quite easily (presumably the commit also vanishes from their repo when they next pull?)
- K0nserv 10y agoI think that's an unfair characterisation of git. Pretty much everything you can read online recommends against force pushing and it's definitely not part of any workflow recommended to beginners. Even with a force pushed branch when the person whose work has been overwritten tries to pull the pull will get reject and they'll retain the local copies of their commits. It's possible to resolve this problem as long as the person with overwritten commit doesn't delete their local copies. Force pushing is super powerful when you learn to use git properly, but it's also like a gun with no safety so it's easy to shoot yourself in the foot if you don't know what you are doing.
- daxelrod 10y agoNo, the commit doesn't just vanish when they pull. They'll be asked to reconcile their local repo with the diverged upstream.
- depr 10y agoI agree, Mercurial is a lot better in this regard.
- saidajigumi 10y agoNote that you should only ever do this if you are absolutely sure that you are the only person pushing to that branch. I've worked with multiple orgs where the convention for shared repos was to use branch names of the form <user>/<topic>, e.g. bowie/pipeline-v2. Such "user" branches should generally never be pushed to by anyone other than the dev they were named for. This has worked great to allow individuals to have visibility and/or backups of work-in-progress while avoiding lossage due to any branch cleanup prior to PR, etc.