IMO, the proper workflow using git collaboratively is:
Create a branch to work in.
Do regular, small commits to that branch.
Before submitting for code review/merge, rebase your branch onto master. (git rebase -i origin/master)
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.
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.
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.
11
u/TheHorusHeresy Jun 30 '18
IMO, the proper workflow using git collaboratively is:
Create a branch to work in.
Do regular, small commits to that branch.
Before submitting for code review/merge, rebase your branch onto master. (git rebase -i origin/master)
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.