Used as a mild oath to express surprise, alarm, etc., or to affirm the truth of a statement; = "Gadzooks".
Late 17th century; earliest use found in George Villiers (1628–1687), politician and wit. From Gad + a second element of uncertain origin.
Are You Learning English? Here Are Our Top English Tips