Having to use substitutes for rosemary doesn’t spell disaster for your recipe, as there are many alternative herbs and spices that can replace both fresh and dried rosemary.
Substitutes for Fresh Rosemary
The best substitutes for fresh rosemary include basil, oregano, and dried rosemary, among others.
Basil possesses a similar size and flavor profile to rosemary, and fresh leaves are readily available around the world. You can use slightly more basil than what a recipe requires in terms of rosemary. 
Oregano has a slightly spicy quality, which is only intensified in the dried form. While this will change the flavor profile slightly away from rosemary, it functions as a good substitute. 
Obviously, the best substitute for fresh rosemary, in terms of taste, would be to use dried rosemary. Since most people have dried rosemary in their spice racks, this is the most common fresh rosemary substitute.
Substitutes for Dried Rosemary
If you want to replace dried rosemary in a recipe, your best options include thyme, tarragon, and bay leaf among others.
Thyme has an aromatic quality that makes it very potent in many dishes, so while it does work as a good rosemary substitute, it can overpower a dish easily. Be sure to use less thyme than the amount of rosemary recommended by a recipe. 
This has an intense and savory flavor, making it a popular replacement for rosemary in flavorful sauces, stews and meat dishes. No more than a teaspoon should be necessary for most recipes.
A single bay leaf can affect the flavor of an entire dish, but it can also mimic the savory spice of rosemary, making it a popular substitute. 
These seeds can be ground into a powder and used as a concentrated substitute for dried rosemary.