Skip to content

Instantly share code, notes, and snippets.

@MathiasSeguy-Android2EE
Created August 19, 2019 13:19
Show Gist options
  • Save MathiasSeguy-Android2EE/714f804e8f1a29d0491c030fcbc1b3bf to your computer and use it in GitHub Desktop.
Save MathiasSeguy-Android2EE/714f804e8f1a29d0491c030fcbc1b3bf to your computer and use it in GitHub Desktop.
Github: Pushing with fallback when id_rsa failed (asking for credential again) in python
#Import dependencies
from subprocess import call
from os import path
from ownStyle import GREEN,BLUE,BOLD,GREEN,RED,RESET,CYAN
#Push the new or update files
# call('git push origin master', shell = True)
#The command line will prompt you
def runGitPushInCommandLine(repository):
# print(repository)
absRepo=path.abspath(repository)
try:
# print(absRepo)
toto=call('git push --force', cwd=absRepo, shell = True)
# print(toto)
if toto != 0:
doitagain=input(RED+"try again ? [y (for yes) else ==no]\n")
if doitagain in "y" or doitagain in "Y":
runGitPushInCommandLine(repository)
print(BLUE+"ok")
else:
print(GREEN+"Project has been pushed on GitHub, congrats.")
except:
doitagain=input("try aggain ? [y (for yes) else ==no]\n")
if doitagain in "y" or doitagain in "Y":
runGitPushInCommandLine(repository)
print(BLUE+"ok")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment