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
Git rebase -i
to squash, reorder or even drop commits and to improve commit messages;Git reset --soft
to remove changes from the Git history but not from the files, and then commit them incrementally in a smarter way than when I was in phase 1.Git push -f
which is fine since my branch is mine only until I mark the PR as ready to review. š
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">-
And I was so embarrassed when a PR of mine was merged without being squashed. ā©ļø
-
If youāve ever reviewed a PR by Hugo you have to know what I mean! Such good story-telling in commits! ā©ļø
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.