Hey this is a really good question thanks!!! So i actually have a lot of  opinions about this. First, I'm going to share generally how to stay  motivated. Then I'm going to share specifically how to stay motivated in  projects. I feel like the second one builds on from the first one.

This  is divided into two camps, sprints and jogging. When you run a  marathon, you don’t sprint all the way to the end. You jog and sprint  when it’s needed for you to win. Like in life, you can’t sprint 100% of  the time.

If you see people who sprint 100% of the time, either  they’re lying through their teeth or they jog so much that their jogging  pace looks like a sprinting pace to you. That’s okay, we all want to  increase our jogging speed.

Now, you want to minimise the amount  you sprint. The way to do this is to batch your work in such a way you  only sprint once every few days / a week at most.

I do this by  automating myself out of failure. If I try to come up with a good  instagram caption / photo every day, I’d fail so fast. Instead, I spend a  few hours a week making all the posts for that week. I know I’m going  to fail, so I automate myself out of this failure.

By sprinting  at pinpoint precision and working smartly you end up doing more than  what is possible if you sprint all the time. Other things you can  automate include emails, food (meal prep), travel etc. Basically, if it  doesn’t bring me joy but it’s essential for me to do, I’ve likely  automated it in some way (or it can be automated).

Once you’ve  done this, what you’ve got to know is that every single human is  different. Some prefer to wake up at 5am, I wake up at 12pm and go to  bed late. Do not copy other people. Experiment with yourself and find  out what works for you.

One of the ways you can automate more of  your life is by experimenting. I found that light coloured photos on  instagram do better than darker. For every 3 dark photos i post, 1 light  photo would get the same amount of engagement. By experimenting i’ve  reduced how much I have to automate.
When you automate a slow  process, you just have a slow process automated. When you automate a  fast process, you’ve 10x that process. Experimenting is key, always.

Now,  when you have to sprint, there are a couple of things you can do. I  like having people depend on me. Knowing that if I don’t finish my  newsletter by Monday, people will be disappointed. People depending on  you is the ultimate form of motivation.

Sometimes, we’ve just got  to be such fucking babies and just do it. There are some things in my  life that i think over for weeks before doing them. If I just do it,  it’s over and i can work on other things.

The best way to do something you dont want to do:
1.  Go somewhere (the worse the better. Neil Gaiiman locks himself into a  1* hotel in the middle of nowhere infested with cockroaches. He doesn’t  leave until he writes his book, good motivation). Personally i prefer  libraries / coffee shops. But you need to be around other people who are  also working. Your natural instinct is to follow the group. Note: if  you’re tired, drink water first. At least a litre. If you’re still  tired, coffee or a nap. Coffee should be the last thing you drink.  Ifyou’re tired because you’re dehydrated, coffee will only make it  worse.
2. Get rid of everything that is absolutely not essential to the task at hand. Nothing to distract you.
3. Just do it.
4.  Relax. The worst motivator is being mentally tired and burnt out. Relax  often. This has to be a daily thing, to relax, to unwind.

Now, we discussed earlier:
"One persons jog is another persons sprint"
How do you get your jogging level to that where it looks like you're sprinting to others?
Work 1% every day. Every single day. write one line of code. Write one sentence. 1% every day.

I  read this study (I can't think of the name of the top of my head) about  how working out 7 times a week for 10 minutes is better than working  out once a week or 70 minutes, as it builds up your jogging level.

Now, how do you stay motivated in a project?

What you want to do is build a minimal viable prodoct. Everyone feels motivated at the start.

When  you're at the start, plan everything. Psuedocode for all the major  functions, plan it as much as you can. Use this motivation at the start  of a project to understand your project. I find that I leave a project  after 1 or 2 weeks if I don't really know where I'm going. If I plan it  all at the start, I have a concrete plant of what to do.

Understand  where your MVP ends. You know where it ends. and you know the  psuedocode / classes etc that you need to get to that end. If you follow  on from earlier, you start out by sprinting.

Then, after  sprinting, jog. 1 or 2 lines of a code a day. thats it. even if you're  sick of it and bored. 1 or 2 lines a day. Those lines eventually add up.  Those 1 or 2 lines could be print statements, everyone has time to add  print statements.

Now, when you have an MVP, release it into the  wild. Building on what I said earlier, you'll have people use your  project. They will depend on you. You now have users. You can't give up  now? With all these people interested in your project.

My largest / most popular github repos all have issues on them. In fact, some of them don't even work properly.
https://github.com/exgen-code/Exgen
https://github.com/brandonskerritt/HowToGetAnyJobYouWant
https://github.com/brandonskerritt/Ciphey

So  now, you've been jogging for a while. You have an MVP. Which, btw, you  can totally talk about your MVPs in interviews as actual products. Even  better if you have a few users too. Doesn't matter if it doesn't work,  you've still made stuff!

The combination of jogging / having  users / people knowing your project exists and expect more should be  enough motivation. Maybe you'll want to sprint again. Maybe you've  decided "well, that was fun. The MVP is all I want to do".

So the most important things to do:
1.  When you start a project, don't start by code. Start by planning. Know  where your MVP ends (and make it easy). Know how to get to that MVP.
2. Once the MVP is made, release it. Start jogging.
3. Whatever you want. It's okay to not complete projects. Maybe you want to complete them, so perhaps you should sprint again.

If  you lose motivation before you finish your MVP, reduce the MVP down  even more. Make it so your goal is closer, so your MVP is closer to  where you are right now. Or just jog until you reach the MVP.

Hope this has helped you :)