Site icon R-bloggers

The two phases of commits in a Git branch

[This article was first published on Maƫlle's R blog on Maƫlle Salmon's personal website, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

I seem to have at last entered my Git era. šŸŽ‰ Reading and applying Git in practice was probably the best thing I did for my upskilling this year. One Git workflow aspect Iā€™ve finally realized is that itā€™s fine to have two phases of work in a Git branch. Iā€™ll explain it in this post.

Set up: create a branch for your work!

Ideally, in most cases, when adding a feature or fixing a bug or whatever, Iā€™ll work in a branch.

gert::git_branch_create("feature")

I really like running the code above as I feel it puts me in the right mind space. I signal my intention to work on a given issue to the universe, it canā€™t hurt, right. šŸ˜

Phase 1: do not think about a clean Git history nor your reputation, just commit all the time

Now, even if I might already open a draft PR to signal my working on a given thing, I just do the thing and try to not think about looking stupid with 1,000 commits ā€œtry to make R CMD check happyā€. I absolutely do not want to lose my work so I commit (with RStudio IDE tab) and push (with gert::git_push() or that same tab) regularly. In this phase, Git is merely my backup.

Phase 2: clean up!

Thatā€™s the phase I used to never do1 but that Iā€™m trying to consciously practice. I guess blogging about this will force me to keep doing it.

In the comments of my reading notes on Git in practice, one of my Git models, Hugo Gruson2, recommended the post ā€œWrite Better Commits, Build Better Projectsā€. The kind of posts I used to think were for other people since I did not understand half of the Git words in it. šŸ˜‰ (Have I mentioned reading a Git book was life-changing? šŸ˜…)

Basically once you have your PR code ready, you have to try and create nice commits, in a nice order. Itā€™s important both for the people that will have to review your code (which might even be just you in a few days for lack of collaborators), and for the people who might have to perform a Git bisect-ion or some other form of archeology on the code base later (again, this might be you).

Part of the work is thinking about what a good set of commits might be.

Then in practice Iā€™ll use

Conclusion

In this post I explained how I now think as work in a branch as happening in two phases, one phase where Git is my backup, and one phase where I try to think more about code reviewers (for the PR) and code archeologists (for later when the PR is merged). Iā€™m still very much learning so donā€™t think youā€™ll get perfect PRs from me just yet!

< section class="footnotes" role="doc-endnotes">
  1. And I was so embarrassed when a PR of mine was merged without being squashed. ā†©ļøŽ

  2. If youā€™ve ever reviewed a PR by Hugo you have to know what I mean! Such good story-telling in commits! ā†©ļøŽ

To leave a comment for the author, please follow the link and comment on their blog: Maƫlle's R blog on Maƫlle Salmon's personal website.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Exit mobile version