import subprocess dch = open("debian/changelog").read().split("\n") ver = dch[0].split(") UNRELEASED")[0].split(" (")[1] print(ver) tag = "upstream/"+ver; subprocess.call(["git","tag",tag]) subprocess.call(["git","push","origin",tag])