Git connect using ssh on windows - windows

I have read some questions around but still didn't found the solution to this problem
I have git on windows and I want to connect to github using ssh.
Following this tutorial https://help.github.com/articles/generating-ssh-keys
I have successfully setup my keys
If I open a git-bash and try to ssh github I am able to connect, so this works
ssh -T git#github.com
Hi username! You've successfully authenticated, but GitHub does not
provide shell access.
this means that git-bash actually sees my keys. However if I try to do a push
git push origin master
git prompts me for username and password
Thank you for your help
EDIT: solved by using the git protocol instead of the http protocol, my fault
so replace this
https://github.com/_user_/_repository_.git
whit this
git#github.com:_user_/_repository_.git
in the remote link

No need to remove/add, just do something like this:
git remote set-url origin git#github.com:username/repo.git

You probably cloned a remote that uses the https protocol, rather than the git protocol. You need to redefine your remote for origin.
# Change this as needed.
github_username="$LOGNAME"
# Replace your remote, then push.
git remote rm origin
git remote add origin "git#github.com:${github_username}/${PWD##*/}.git"
git push --tags --set-upstream origin master

Related

Pushing commits to an SSH-cloned repo via VS Code on WSL returns "Host key verification failed" - it's ok on HTTPS

I'm on a Windows 10 machine and I have both Git Bash and Ubuntu for Windows Subsystem for Linux (WSL) installed. When I use GitHub's official desktop app to clone a repo via HTTPS everything works fine and I can push my commits via Visual Studio Code with no problems whatsoever. I then try to clone a repo via SSH with Hyper (WSL Bash) and get this:
The authenticity of host 'domain.com (a.b.c.d)' can't be established.
RSA key fingerprint is XX:XX:...:XX.
Are you sure you want to continue connecting (yes/no)?
After answering yes and openning that repo in VS Code and try to push my new changes to GitHub, I get this error:
Git: Host key verification failed.
And this is what I get as Git Log in Output:
Host key verification failed.
fatal: Could not read from remote repository.
I have set up my SSH key on WSL using this method and I didn't set up any passphrase. I tried this on my brother's PC which is exactly set up like mine and it worked just fine. I would appreciate any help!
UPDATE: I typed ssh -T git#github.com in Hyper and got this as an answer: You've successfully authenticated, but GitHub does not provide shell access.
P.S. I'm a newbie in programming and stackoverflow, so please be concise and give me step by step instructions. The more you use technical terms, the more I'll probably get lost!
Try first, for that new push, to do it in command line:
cd c:\path\to\local\repo
git status
git log
git remote -v
git push -u origin master
Make sure that:
git status is clean (no pending changes)
git log shows you at least one commit
git remote -v shows you as origin the URL of your remote GitHub repository
(as an SSH URL git#github.com:<you>/<yourRepo>)
Then push, and go back to VSCode.
Should be faster than the other solution:
In vscode open a new terminal of type "Command Prompt"
Run: git push and accept the new key when prompted.
This will store the remote key for future use.

GIT commands to automate repo mirroring

I'm working for a client who has their own secure git repository, which is only accessible by a VPN connection. My company has its own secure VPN, where our GIT server resides. Some colleagues don't have access to the client's repo and updating our repo is very time-consuming.
I wrote a small sh script that asks us to connect to the client's VPN, and once connected it fetches all relevant repos. The script then asks us to disconnect and connect to our own VPN, after which the script must push the changes.
I'm having trouble with this last part. How can I have git push everything I just fetched? This is not only the typical "develop" and "master" branches but also new branches with unknown names (e.g. newFeature/XXXX, where XXXX is unknown and can change).
Thanks in advance for your help!
See "Set up git to pull and push all branches", which includes, as commented:
git push --all origin
In your case:
git push --all -u
if you add -u once, e.g. git push --all origin -u, tracking is setup and after that you can simply use git push.

Push Changes to Git not Functioning

Every time I want to commit the command "git push heroku master" I am asked in the PowerShell to enter the credentials. When I enter heroku credentials (which is connected to git by default) I get the error message.
But, when I type the credetials contained in the netrc file in my home directory, then the thing functions. The password is however hashed in my opinion. How can I avoid entering credentials every time I want to push changes to git?
UPDATE:
PS C:\Users\Dragan\heroku_workspace\python-getting-started> git push heroku master
github --credentials get: github: command not found
Username for 'https://git.heroku.com': my-email#hotmail.com
Password for 'https://my-email#hotmail.com#git.heroku.com':
github --credentials erase: github: command not found
remote: ! WARNING:
remote: ! Do not authenticate with username and password using git.
remote: ! Run `heroku login` to update your credentials, then retry the git command.
remote: ! See documentation for details: Https://devcenter.heroku.com/articles/http-git#authentication
fatal: Authentication failed for 'https://git.heroku.com/mysterious-river-71834.git/'
A common mistake is cloning using the default (HTTPS) instead of SSH. You can correct this by going to your repository, clicking the ssh button left to the URL field and updating the URL of your origin remote like this:
git remote set-url origin git#github.com:username/repo.git
or if your repository already then click green button CLONE OR DOWNLOAD and select use SSH
Enable SSH authentication
$ heroku create --ssh-git
Redirect tall HTTPS calls to SSH ( If you want to always use SSH Git with Heroku on a particular machine)
$ git config --global url.ssh://git#heroku.com/.insteadOf https://git.heroku.com/
To generate a public key:
ssh-keygen -t rsa Press enter at the first prompt to use the default file location. Next, type a secure passphrase for the key.
If you are using v1.9.3 or later Git for Windows, you can do the following
git config --global credential.helper wincred
Please note that this mechanism stores your username/password in Windows Credential Store.
In relatively newer versions, Git Credential Manager for Windows is bundled with Git for Windows and enabled by default, you might have to override credential.helper configuration for Heroku. GCM seems designed for VSTS and GitHub and I am not how it will behave with other servers.
Worked for me:
Run heroku login using the windows command prompt cmd.exe. This will drop your API key into your _netrc at which point you can open up cygwin or git bash and do whatever you need to
From .gitconfig remove the helper = manager line so that it is no longer registered as a credential helper and stops it from showing up.
(in C:\Users\username\.gitconfig )
Rename _netrc file to .netrc on Windows 7 in the user dir:
cd %home%
REN _netrc .netrc
see:
'git push heroku master' is still asking for authentication
https://github.com/heroku/cli/issues/84#issuecomment-170689175

Git push not working but "git clone" and SSH does

I set up a Debian server that uses SSH for shell access and git repos. I created a bare repo on it and using ssh was able to clone it to my Windows 8 workstation, however when trying to push changes back to the Debian server I get the error depicted here:
Read from remote host 174.52.5.192: Connection reset by peer
fatal: sha1 file '<stdout>' write error: invalid argument
fatal: The remote end hung up unexpectedly
error: failed to push some refs to 'git#174.52.5.192:/home/git/repos/space-junk.git/'
I use this work station regularly for shell access to the same server via SSH so I know inability to access SSH isn't the problem.
Does anyone have any idea what's going wrong?
Actually, the first push should be:
git push -u origin master
That will link the local branch master to its remote tracking one origin/master
Then, after that first push, you will be able (for all the subsequent push) to do a simple:
git push
See more at "Why do I need to explicitly push a new branch?".
I got it working! It turns out the proper command was
git push origin master
The Windows version didn't have a descriptive enough error message but I got it working by switching over to Linux, which told me my command was wrong.

Can't push branch to github "Use git#github.com:Paratron/spacebattles.git"

I have a working branch in my Mac names database and I would like to push this branch to GitHub and have tried to do this by running:
git push -u origin database
And get the following error message:
You can't push to git://github.com/Paratron/spacebattles.git
Use git#github.com:Paratron/spacebattles.git
Are there known issues that could be the cause for this?
Are there any likely errors I could be doing that results in this error?
Like it says, you can't push to git://github.com/Paratron/spacebattles.git (because it's a read-only URL). Try this:
git remote set-url origin git#github.com:Paratron/spacebattles.git
git push -u origin database
If you haven't ever used git in this way, you need to set it up to work with GitHub first: http://help.github.com/mac-set-up-git/
Also, are you Paratron? If not, you'll need to fork his repository first: http://help.github.com/fork-a-repo/. Then you'll need to use your username instead (git#github.com:YOUR_USERNAME/spacebattles.git).
The URL that you have set for the repository is a readonly URL. You'll need to change the URL for the remote, using remote set-url:
git remote set-url origin git#github.com:Paratron/spacebattles.git

Resources