to get ahead of yourself or jumping the gun are interchangeable.
but "jumping the gun" means starting or to begin too early. It comes from sprint racers leaving the starting blocks before the starting gun is fired, because the runners/sprinters are all excited and fired up.
Getting ahead of yourself although often used interchangeably means trying to do something before you are ready, or deciding to do something because you don't have the information to make a correct decision - for example receive the correct training.
you are told to be somewhere and begin a job at a certain time, you arrive earlier and begin the job. then a little later a delivery arrives with important things you need to do the job, and the boss finds out. He would say you jumped the gun. Because now you have to start again and use/install the things that have just been delivered. You jumped the gun.
You start a new job and want to impress, so you decide to move some boxes that seem to be in the way. Then it latter turns out the boxes have to be there in that position for a reason, because where you have now placed the boxes is about to be covered in three feet of concrete for a new floor. So the boxes have to be taken back to where men worked hard last night moving them to. You got ahead of yourself. You did not start too early but you made wrong decision because you did not have the knowledge or training or experience.