It's like meditation: if you get distracted accept it and bring your attention back to the task at hand… Over the long run you'll be more focused!
My concentration last for about 30 minutes and so i will use a timer set at 25 minutes to focus on what I should be doing. After that, I'll use the remaining 5 minutes to take a break. If it's a long task, I'll do the cycle over and over until I'm ready to call it a day.
Go away from distractions. Go to cafe, wear headphones with noise cancellation, hide smartphone from your view. In addition to it, take 5 minutes rest after 25 minutes work to keep your concentration.