Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change git ssh user for a remote push temporarily?

Tags:

git

ssh

push

Is it possible to change the ssh user temporarly for a "git push remote master" without messing up with .git/config or "git remote", or using the whole remote url?

[root@host gitrepo]# git push otheruser@remote master # this does not work, but how great it would be [root@host gitrepo]# USER=otheruser git push remote master # still asks password for root 
like image 491
Andor Avatar asked Mar 21 '13 15:03

Andor


People also ask

How do I push to a different git account?

Push as same username, but to different github accounts After this, if you'll push using git push -u origin-username master , this will prompt you for the password. This is a good trick for multi accounts.

Is it possible to change SSH user temporarly for Git push remote Master?

Is it possible to change the ssh user temporarly for a "git push remote master" without messing up with .git/config or "git remote", or using the whole remote url? Have you tried using the whole remote URL? Yes, I've tried it. Usually I copy-paste from "git remote -va". It works, though it creates an additional remote tracking branch on pulls.

How do I push to a git repository from another server?

You can push to git repository which is on remote ssh server using git. You can configure remote repository as a git remote to be able access quickly using remote (short) name.

How do I push changes to a remote git branch?

server is remote configured using git remote command master is the branch to push When you push changes, you will be prompted for the password. You can configure ssh keys to bypass password authentication when you push changes.

How to push from another user's GitHub account?

If you use different windows user, your SSH key and git settings will be independent. If this is not an option for you, then your friend should add your SSH key to her Github account. Although, previous solution will keep you pushing as yourself, but it will allow you to push into her repo.


2 Answers

Have you tried using the whole remote URL?

git push ssh://<temp_user>@<host>/<repo_path> <local_branch>:<remote_branch> 

and you will be prompted to provide the password

like image 56
laplasz Avatar answered Oct 09 '22 12:10

laplasz


Once you've done the commit, you can use the following syntax:

git push https://<username>@github.com/<github repository> <local branch name>:<remote branch name> 

You'll be asked for your github password to process the push.

For example, if your github username is "foobar", the repository clone url is "https://github.com/bar/ish.git", and the local and remote branches are named "nonce", you can use the following:

git push https://[email protected]/bar/ish.git nonce:nonce 
like image 35
Jesuisme Avatar answered Oct 09 '22 11:10

Jesuisme