automating to push changes to github for multiple repos using python This Python script does following activities:


clone repo, as provided from the list
creating a new branch "jenkinsMigrate"
rename Jenkinsfile to Jenkinsfile.migrate 
push code to GitHub in a new branch.


NOTE: credentials were configured already.

import git
import os
import subprocess

gitUrl = "https://*****"
cwd = "*****"

with open("migrateList.txt", "r") as file:
    for line in file:
        #configure gitUri for each repository
        gitUri = gitUrl + line.strip() + ".git"
        try:
            global repo
            repo = git.Repo.clone_from(gitUri, cwd + line.strip())
        except:
            print(" directory already available")
        os.chdir(cwd + line.strip())

        #checkout new branch for migration
        repo.git.checkout('-b', "jenkinsMigrate")

        subprocess.call(["git", "mv", "Jenkinsfile", "Jenkinsfile.migrate"])
        repo.git.add(update=True)
        repo.index.commit("jenkins migration")
        origin = repo.remote(name='origin')

        #push new branch to github
        subprocess.call(["git","push", "--set-upstream", "origin", "jenkinsMigrate"])
        subprocess.call(["cd", ".."])


Sample text file:

$ cat migrateList.txt 
repo1
repo2
repo3
repo4


This is a working code, but all I am looking for is to maintain consistency in the commands that I use. eg: For some of the git commands that I have used are from gitpython module where as others are invoked with shell commands. Apart from these any other suggestions are welcome.

Thanks!

UPDATE 1: python - 2.7.10

gitPython module
Review


Stick to the PEP8 style guide


Functions and variables should be snake_case
Constants like gitUrl should be UPPER_SNAKE_CASE

There is a function for getting the current working directory

os.getcwd() Depending on your use case this might be useful
If you are using Python3.5+ you should change the older subprocces.call with the newer subprocess.run
Don't catch bare Exceptions

If you now what exceptions are going to be caught it is better to define them