Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How do I push commits to a local repository with an SSH key? #1203

Answered by Byron
jmkd3v asked this question in Q&A
Discussion options

I have a local repository that I've already cloned and I want to push changes to remote (GitHub) from a different account.
I've tried something like this:

id_file = os.path.expanduser('~/.ssh/id_rsa_api')
id_cmd = "ssh -i " + id_file
repo = Repo(path)
with repo.git.custom_environment(GIT_SSH_COMMAND=id_cmd):
 # rest of code here

but it's had no effect - the commits always are pushed under my main GiitHub account, no matter what SSH key I use.

You must be logged in to vote

@jmkd3v wrote

Update: I was able to solve this problem by deleting my GitHub credentials and then changing my email and username on the local level.

Replies: 2 comments 2 replies

Comment options

Did the GIT_SSH_COMMAND environment variable have an effect when running git on the command-line directly?

From the code I see here I would expect this to be picked up when interacting with remotes.

You must be logged in to vote
2 replies
Comment options

Odd - it does not apply in the command line either. Maybe I should remove my main account from Git and try again?

Comment options

Update: I was able to solve this problem by deleting my GitHub credentials and then changing my email and username on the local level.

Comment options

@jmkd3v wrote

Update: I was able to solve this problem by deleting my GitHub credentials and then changing my email and username on the local level.

You must be logged in to vote
0 replies
Answer selected by Byron
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants

AltStyle によって変換されたページ (->オリジナル) /