Wed 16 Sep 2009
Git – Fixing a Defect
It’s Tuesday morning and a bug has just been found in production. We were about to start working on a user story, but we need to switch gears and fix this bug.
Our repository currently looks like the following.
BRANCH
|
(A) -- (C)
(B) -- (D)
|
*master*
We need a topic branch based on BRANCH so that we can fix this bug.
git checkout -b DE1234 BRANCH
*DE1234*
|
BRANCH
|
(A) -- (C)
(B) -- (D)
|
master
We find and fix the defect. After committing the fix, our repository is in the following state.
BRANCH *DE1234*
| |
(A) -- (C) ---- (E)
(B) -- (D)
|
master
We need to integrate our fix with origin/BRANCH. The workflow for this integration is very similar to the user story workflow.
If you want to read a full explanation, read the first article in this series.
git fetch git rebase origin/BRANCH
BRANCH origin/BRANCH *DE1234*
| | |
(A) -- (C) ------- (F) --------- (E')
(B) -- (D)
|
master
git push origin HEAD:BRANCH
origin/BRANCH
|
BRANCH *DE1234*
| |
(A) -- (C) -- (F) -- (E')
(B) -- (D)
|
master
After the above series of commands, we have integrated and pushed our changes to the origin BRANCH. We now need to merge our changes to the master branch.
We need to ensure that our local BRANCH has all of our changes.
git checkout BRANCH git pull
origin/BRANCH
|
*BRANCH*
|
(A) -- (C) -- (F) -- (E')
(B) -- (D)
|
master
We now need to pull changes for master.
git checkout master git pull
origin/BRANCH
|
BRANCH
|
(A) -- (C) -- (F) -- (E')
(B) -- (D)
|
*master*
|
origin/master
We are ready to merge.
git merge BRANCH
origin/BRANCH
|
BRANCH
|
(A) -- (C) -- (F) -- (E') --+
\
(B) -- (D) ----------------- (G)
| |
origin/master *master*
Our changes have now been merged into the master. We still need to push our merge to origin’s master.
git push origin master
origin/BRANCH
|
BRANCH
|
(A) -- (C) -- (F) -- (E') --+
\
(B) -- (D) ----------------- (G)
|
*master*
|
origin/master
We have successfully merged our changes from the branch and pushed them to the origin. We are now ready to start on our user story.

Your links to the user story workflow are broken.
Thanks. I fixed the problem.
[...] Git – Fixing a Defect » Engineering Blog [...]