Have you tried keeping a document logging what your thoughts/steps while doing a task were? I find this helps me stay on track. You don't need to write it in a clean way, just bullet points to reconstruct the steps you've taken, progress, decisions you need to take etc.
You can start with something as simple as "I downloaded the code from 'X', 'Y' is the shell command I used to build the project, now how do I reproduce bug 'Z'? Is there an existing script I can run or do I need to ask someone for a command, blah blah"...
I find this is very useful when working on unfamiliar tasks or when I'm finding it hard to get traction on a task (due to procrastination or anything else). Just writing something has a way of making yourself get any clarity you can, and if you lose traction again, the notes you wrote are something you can use to get started again.
It's quite freeing to not have to have all the context in your head all the time.