2021年3月13日星期六

Push a git repo to Gitlab not using the global settings

I am trying to push a git repo to Gitlab.

I have --global git and ssh settings that I use for work. The one repo I am having problems with is a personal project so I want to use a different user.name and user.email git config settings and a different ssh key pair to my global work config.

I have set the user.name and user.email in the git repo (without the --global switch) using:

git config user.name "my gitlab username"  git config user.email "my gitlab registered email address"  

I have set the git config to use the local ssh key file instead of the system one using:

git config core.sshCommand "ssh -o IdentitiesOnly=yes -i ~/path-to-ed25519 -F /dev/null"  

On gitlab I have created a repo with the same name as the local repo and I have added the ssh public key.

Gitlab recommends these commands to push the project:

cd existing_repo  git remote rename origin old-origin  git remote add origin git@gitlab.com:project.git  git push -u origin --all  git push -u origin --tags  

The git remote add origin git@gitlab.com:project.git command seems to succeed, no errors at least. The git push -u origin --all command fails with the following output:

No refs in common and none specified; doing nothing.  Perhaps you should specify a branch such as 'master'.  fatal: the remote end hung up unexpectedly  Everything up-to-date  

Gitlab recommends testing the ssh setup with ssh -T git@gitlab.example.com but it is not clear to me how to populate the example.com from the repo url. I have tried all the obvious combinations but no joy. I have also tried the -i option to specify the private key to use and the -Tvvv option instead of the -T option but it is not clear if this is working. The output looks like:

OpenSSH_7.6p1 Ubuntu-4ubuntu0.3, OpenSSL 1.0.2n  7 Dec 2017  debug1: Reading configuration data /etc/ssh/ssh_config  debug1: /etc/ssh/ssh_config line 19: Applying options for *  debug2: resolving "gitlab.com:username/project" port 22  ssh: Could not resolve hostname gitlab.com:username/project: Name or service not known  

Any and all help appreciated...

https://stackoverflow.com/questions/66619423/push-a-git-repo-to-gitlab-not-using-the-global-settings March 14, 2021 at 07:02AM

没有评论:

发表评论