Git is for 1. Helping with conflict resolution when multiple people work on a piece of code, and 2. Tracking changes to software over time, to aid in bug fixing, patching older versions, and understanding why the code looks the way it does.
If you're intentionally committing code that doesn't work then you are ruining both the ability for others to work with the code, and your own ability to use the history for anything.
You _can_ use it as a poor man's backup solution (I do this myself), but the key then is to have a clear separation between a "work in progress" branch that only you work in, and the collaborative or long-lived branches. Before you merge a work-in-progress branch (or make a pull request), you need to make sure that each commit that remains passes the unit tests. You can use an interactive rebase for this.
The problem with Git is that it is actually a rich man's backup solution. It lets you do very detailed snapshotting and manipulation across versions. So when working on something it can be very helpful to have many commits during the work.
But I agree that it is usually best to then "refine" those into nice, working, logical chunks before sharing with others.
winternewt|1 year ago
If you're intentionally committing code that doesn't work then you are ruining both the ability for others to work with the code, and your own ability to use the history for anything.
You _can_ use it as a poor man's backup solution (I do this myself), but the key then is to have a clear separation between a "work in progress" branch that only you work in, and the collaborative or long-lived branches. Before you merge a work-in-progress branch (or make a pull request), you need to make sure that each commit that remains passes the unit tests. You can use an interactive rebase for this.
kevincox|1 year ago
But I agree that it is usually best to then "refine" those into nice, working, logical chunks before sharing with others.
harperlee|1 year ago
Share finished bits of work that help others; keep the snapshot of your messy workshop with the table full of things and tools on a private branch.