I only use rebase workflow, because it is visually clearer(not only in GitKraken, but also in Intellij and in gitk
, but I recommend the first one most): you have a branch, it originates from the master, and it goes back to master. When the diagram is clean and beautiful, you will know that nothing goes to hell, ever.
My workflow is almost the same from yours, but with only one small difference: I squash
commits into one in my local branch before rebase
my branch onto the latest changes on master
, because:
rebase
works on basis of each commit
which means, if you have 15 commits changing the same line as master
does, you have to check 15 times if you don't squash, but what matters is the final result, right?
So, the whole workflow is:
Checkout to master
and pull to ensure that you have the latest version
From there, create a new branch
Do your work there, you can freely commit several times, and push to remote, no worries, because it is your branch.
If someone tells you, "hey, my PR/MR is approved, now it is merged to master", you can fetch them/pull them. You can do it anytime, or in step 6.
After doing all your work, commit them, and if you have several commits, squash them(they are all your work, and how many times you change a line of code does not matter; the only important thing is the final version). Push it or not, it doesn't matter.
Checkout to master
, pull
again to ensure you have the latest master
in local. Your diagram should be similar to this:
As you can see, you are on your local branch, which originates from an outdated status on master
, while master
(both local and remote) has moved forward with changes of your colleague.
master
and choose "Rebase"; another reason why I like it.)
After that, you will be like:So now, you have all the changes on the latest master
, combined with changes on your branch. You can now push to your remote, and, if you have pushed before, you will have to force push; Git will tell you that you cannot simply fast forward. That's normal, because of the rebase, you have changed the start point of your branch. But you should not fear: wisely use the force, but without fear. In the end, the remote is also your branch so you do not affect master
even if you do something wrong.
Create PR/MR and wait until it is approved, so master
will have your contribution. Congrats! So you can now checkout to master
, pull your changes, and delete your local branch in order to clean up the diagram. The remote branch should be deleted too, if this is not done when you merge it into master.
The final diagram is clean and clear again: