I make this mistake quite frequently and I am wondering if there's a better solution, and also whether my current solution is risky.
Here's the workflow
- git checkout master
- git pull
- git submodule update --init --recursive
- (edit, debug, test)
- git commit -a
- git push origin HEAD:refs/for/master
- (more edit, test, etc.)
- git commit -a
- gitk
- (swearing)
- git rebase -i HEAD~2 # pick and squash my two commits together
- git checkout -b task_id
- git checkout master
- git rebase -i HEAD~2 # pick previous user's commit, delete my own
My mistake is that somewhere around step 5 I should be doing something like step 12 to create a new branch to keep this work separate from every other task, to allow me to easily come back to it or rebase different patches in the desired order or whatever. Instead, I am pushing new code onto the master branch, and around about step 10 I realize that master
is no longer pointing at the latest and greatest version of the code that the company has approved, but my own efforts. So after squishing my own commits into one with an interactive rebase
, I'm doing another interactive rebase
to get master
pointed back where it should be -- namely, someone else's work that has been through the review process.
Edit to clarify: When I "push to master" this doesn't publish my changes to everyone else. There's some commit hook magic that creates a Gerrit code review task and only when approval is obtained from that is my commit merged into the remote repository. Apologies for misleading you all. My concern here is only for my local repo.
My question is twofold. How bad is this practice, in terms of risk, and how could it be improved upon? I'm not asking for help in avoiding the initial error. I think I just need to be more careful about which branch I'm pushing to. The question is how best to point master
at the previous commit without disturbing/risking/losing anything.