Ideally for the branch per ticket work-flow you make zero changes to your master branch and make all changes on ticket branches. You also have to maintain a committed revision (which you amend as you go) i.e. a single commit per branch.
This allows working on multiple tasks in parallel with clean separation of changes.
git checkout -b ticketname master
— Creates new branch from master with the name «ticketname» and switches to it- Make modifications to files
git status
— Check what files need to be addedgit add filename1 filename2
— Add modifications or new files to the staging areagit commit -m "Commit message"
— Create your commit — further commits on this branch use--amend
to modify this commit e.g.for review fixes or switching branches- Make modifications to files again if needed
git add filename1 filename2
— Add modificationsgit commit --amend
— Amend your first commmit with new modifications. Repeat 6-8 steps as many times as needed.git checkout master
— Go back to mastergit pull origin master
— Update the master branch with the latest changes from other developersgit checkout ticketname
— Switch back to your branchgit rebase master
— Bring your ticket branch up to date with the latest changes and move your commit to the top of the history (make it latest)- If rebase fails you will be dumped to «no branch» go to «13.1», is successful go to «14»
git status
— See what files failed to merge- Make modifications to failed merges
git add filename
— Add fixed filesgit rebase --continue
— Finish the rebasegit checkout master
— Go back to mastergit pull origin master
— Pull again to be sure nobody commits new changes in master while you merging files. If new commits pulled go to step «11» and rebase again
git checkout master
— Go back to mastergit merge ticketname
— Merge branch «ticketname» to «master»git push origin master
— Push your changes to origin repositorygit branch -d ticketname
— Delete the branch, you can't use it anymore
Do not keep the branch and re-use it after git merge
and git push origin master
as this will mess up the git history.
If you ever will need to work on this feature again (improvements, bugfixes ect.), you should create new branch with the same name.
When working on a ticked by this method for a long time. it's recommended to pull the master and rebase the branch from time to time to update the files with the latest versions.