Sewing a straight line can be a challenge, especially if you are new to sewing. There are several tricks you can use to help you sew straight.
How to keep the fabric from shifting while sewing
Always prep your fabric that you are about to sew before you send it through the sewing machine. Line it up in front of the presser foot and make sure to hold the fabric with both hands and help the sewing machine feed the fabric through.
Sew straight guide

There are several ways you can create or buy a guide to help you keep your seam in a straight line. First, is the lines already on the throat plate of the sewing machine. These markings are in metric measurements. If you are sewing a store-bought pattern, check your instruction sheet to see what seam allowance you should be using. Try to keep the fabric right along the side of that seam line.
There are many presser feet out there on the market you can buy to help you sew straight. Because you would be using the foot as your guide, this means that your seam allowance would not be a lot.
Magnetic sewing guide

You can also purchase an inexpensive magnetic sewing guide that will attach itself to your sewing machine to create a guide. You will use this to bump your fabric edge right up beside the guide. The fabric will run along the edge of the fabric and help you sew a beautiful straight line. Make sure that your sewing machine can use the magnetic sewing guide by taking a magnetic at home that you have lying around or off the fridge to test your sewing machine. The throat plate on the sewing machine is most likely magnetic. So there are different ones you can get. Make sure the one you get works for your specific sewing machine. Some sewing machines have plastic on the outside, and this more extended type of magnetic guide will not work for you.
Sewing hack trick
A good sewing hack is to use painters tape on your sewing machine to mark a guideline. The great thing about painters tape is it is easily removed and will not hurt the sewing machine.
Different presser feet to help sew straight

Edge stitching foot – The edge stitching foot is excellent for sewing straight on the right side edge of the material you are sewing.
Left edge stitching foot – This foot is suitable for sewing a seam or topstitching nice and straight on the left side edge of a fabric.
Blind hemming foot – This foot has a fixed position guide where your fabric will stay under the foot while sewing. It makes it where you can sew a straight line right up against the edge of the material. Stitching this close to the seam edge makes it great for topstitching.
Adjustable blind hem foot – You can adjust where the guide on this foot is from right to left. Thus, making your guide very narrow for stitching straight against the edge or a more significant distance away from the border of the fabric.

Ditch stitching foot / Edge joining foot – This foot has a fixed guide right in the center of the foot. You can use this foot as a guide to bump your fabric up against for sewing straight. Another way to use this foot is for quilting as a stitch in the ditch foot.
Sewing straight lines on a quilt
For quilting, there are a couple of different presser feet you can buy individually for quilt piecing. Along with another presser foot to help you stitch all three layers of the quilt together.
How to sew neatly
The best way to sew neatly is to take your time, don’t rush. Practice sewing some scrap fabric before sewing the real thing. Over time you will be getting more comfortable with sewing straight and neat.
Sewing a straight line by hand
For sewing by hand, you can draw on a line that you can remove at a later time. There are different types of marking pens and chalk for sewing. Some are air disappearing ink where others you need to use water to remove the lines. Try hand sewing right over the top of the straight line you have drawn on the fabric.
Sewing a straight line
Sewing a straight line takes a little practice, but you will get it over a little bit of time.