News for hackers. Stuff that matters.
Re:GitTips by vog on Monday August 15, 2016 @10:12AM (#12290530)
> ... `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".

Re:GitTips by acobster on Monday August 15, 2016 @10:23AM (#12290609)
> 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.

Re:GitTips by 0x0 on Monday August 15, 2016 @10:21AM (#12290597)
push --force-with-lease can mitigate accidental overwrites though
Re:GitTips by vog on Monday August 15, 2016 @11:44AM (#12291176)
Thanks for the hint. I wasn't aware of that option.
Re:GitTips by saidajigumi on Monday August 15, 2016 @01:15PM (#12291790)
Note 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.

Re:GitTips by K0nserv on Monday August 15, 2016 @10:19AM (#12290579)
Definitely, 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
Re:GitTips by meestaahjoshee on Monday August 15, 2016 @10:19AM (#12290581)
You can use --force-with-lease
Re:GitTips by pjc50 on Monday August 15, 2016 @10:57AM (#12290831)
you'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?)

Re:GitTips by K0nserv on Monday August 15, 2016 @11:00AM (#12290865)
I 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.

Re:GitTips by daxelrod on Monday August 15, 2016 @11:02AM (#12290876)
No, the commit doesn't just vanish when they pull. They'll be asked to reconcile their local repo with the diverged upstream.
Re:GitTips by depr on Tuesday August 16, 2016 @05:39AM (#12296366)
I agree, Mercurial is a lot better in this regard.