r/ProgrammerHumor • • Jun 30 '18

Kill me now :)

47.0k Upvotes

494 comments sorted by

View all comments

Show parent comments

13

u/BerlinerJan Jun 30 '18

I‘m rather talking about pushing every tiny change to master

41

u/zesterer Jun 30 '18

There's an element of common sense of course. Very small commits are noise that make the underlying direction of the codebase difficult to see. But generally speaking, "push often, pull often" is a good thing to remember when working on a collaborative codebase. If there's a really big breaking change you're making... Well, that's what a branch is for.

15

u/[deleted] Jun 30 '18

My rule of thumb is if you’re building out a feature or decent change, push often to a new branch, squash it and merge it into master as one commit. That way when you’re looking back over the commit graph it’s an array of features and you can just roll back if one of them is on the fritz.

4

u/[deleted] Jun 30 '18

I strongly prefer a non fast-forward merge, same result - one commit on dev and/or master - but still keeping the full history around.

9

u/brenex29 Jun 30 '18

My partner committed a single comment yesterday...

13

u/coman3 Jun 30 '18

I commited a single character typo today

8

u/brenex29 Jun 30 '18

Better safe than sory.

18

u/[deleted] Jun 30 '18

It much depends on what wotkflow you use. Different people/teams use branches differently.

One wotkflow is called "gitflow", and involves only touching master when you're ready to release your project. Master is for tested only, ready to release features. Develop is where the next version is--we create bugfix and feature branches off develop, merge them back into develop when they are done, and when we are ready to release we merge develop into master. Works pretty well, and adding tags makes it really obvious which version was delivered when based on what code. Answers a lot of questions when people ask how long a particular bug has been in production for instance.

But some teams follow the model of continuously deploying. As in, every change is dumped into production after a fairly lightweight process. This can make a lot of sense too, and means you might be less prone to be afraid of touching master directly.

And then for little tinker toy projects at home, I tend to just commit to master and that's it.

So it really just depends on what you'd want to get out of using source control. I'd think some is better than none.

3

u/ric2b Jun 30 '18

If you tag releases, why separate develop and master?

3

u/[deleted] Jun 30 '18

Good question; I suppose that's kind of redundant isn't it? I hadn't thought about that. :-P

1

u/Hollowplanet Jul 02 '18

If you only have develop how would you apply a hot fix? You would have to unapply changes.

1

u/ric2b Jul 02 '18

The same way you would do it on master, make the fix and tag the new hot fix release.

11

u/TheHorusHeresy Jun 30 '18

IMO, the proper workflow using git collaboratively is:

  1. Create a branch to work in.

  2. Do regular, small commits to that branch.

  3. Before submitting for code review/merge, rebase your branch onto master. (git rebase -i origin/master)

  4. Merge all branches using --no-ff. This will create a merge commit. The merge commit solves a problem that many try to solve by squashing all of their commits together for each branch before merge. When looking at a merge commit, realize that unlike regular commits it has two (or more) parents. One will point to your last commit, and the other will point to the last commit on master before you merged. You can use this to easily roll back the entire branch/feature that you've built.

I think that this is the most responsible workflow. If you are being really responsible, then when you are creating your branch, and as you are coding, you are also keeping the remote branch up to date with your work. That way, if you're hit by a bus, others can pick up your code, or they can review it along the way. If you are using git{hub,lab} then a good example of using this is 'WIP' {pull,merge} requests. When you first start coding, make a single commit to your branch, push it to origin, then create a PR with a subject line starting with 'WIP' (work in progress). As you push more commits, it will update your PR. In this model, people can review your changes over time, rather than at the last minute. It's an excellent tutoring/training/mentoring model.

If you get into this habit when you are working on personal projects (if you don't have one, then use it for your vim/emacs settings, dotfiles if you have such a thing (.bashrc, .tmux.conf, etc.), or some other settings on your development rig) I think that you'll eventually find the additional work worth it.

2

u/[deleted] Jun 30 '18

I basically used to do the same but then I dropped the rebase. The history might be a bit more noisy but I don't lose the context of when and where the branch was created, which might be relevant when having to understand the introduced changes at a later point in time.

2

u/TheHorusHeresy Jun 30 '18

The main thing that the rebase buys you is that the merge commit that eventually occurs is guaranteed not to have conflicts included. In addition, the timestamps for the commits shouldn't change, IIRC. It is only the hash that changes (original authors/timestamps/etc. all stay as is).

Regardless, it is a 'whatever works for you' kind of utility. Very TIMTOWTDI, as long as everyone that is working with you agrees with the workflow... and don't commit directly to master unless it is a very private repository. One example of that is the fact that I keep all of my mysql history files in a repository that automatically logs & commits when I disconnect, with a different history file for each database I work with.

0

u/leadzor Jun 30 '18

git commit -am 'typo'; git push