简体   繁体   中英

Setting up and accessing git on windows 2012

I am using the following computers.

Local machine: Windows 10. I also have windows 7 machines here, but not really using them.

Windows Server 2012 r2 (not in the same physical location). This is not a production server, it's just a server I use for hosting various scripts.

I am currently just accessing the windows server with the IP address. However, if it some how makes this easier, I can assign it a static IP link it to a subdomain.

Obviously using the real IP of the server, but for the sake of this post, I'm using 1.1.1.1

I've set up git on the windows server. I followed: https://www.server-world.info/en/note?os=Windows_Server_2012&p=openssh

I just deleted all the repositories I was testing with, so I could go through it step by step here in hopes someone can point out where I've gone wrong.

I created a user on the server, named 'kannkor', and assigned it a password.

I am currently RDC (remote desktop connection) into the server. So I can do anything, verify from there if I need.

I have putty open, and the connection type is "ssh", the host name is the IP of the server, on port 22. It asks me:

login as: 

I type in "kannkor" It then asks:

kannkor@1.1.1.1's password: 

I type it in. It takes me to:

kannkor@computername C:\Users\kannkor>

I'd like the repositories to be on the d drive. I can change directories:

I create a new folder:

d:
mkdir repos
cd repos

From the RDC, I can verify the repos folder is now created under D: Going through a mental checklist, this means my username/password/permissions to that drive/folder are set.

At this stage, I feel like I've followed 100 walkthroughs, and they all end up the same. So for sake of argument, I'm going to follow this one: http://thelucid.com/2008/12/02/git-setting-up-a-remote-repository-and-doing-an-initial-push/

On the local machine I open a git bash and type:

ssh kannkor@1.1.1.1

It asks me for my password, I type it in.

I do the following (following the walkthrough).

d:
cd repos

I'm now at:

D:\repos>

Maybe this is where I've went wrong, by changing the drive/directory... But it must be possible.. continuing with the walkthrough

mkdir my_project.git
cd my_project.git
git init --bare
-> Initialized empty Git repository in D:/repos/my_project.git/

I did the git update-server-info (I've tried it with, and without, and had no impact on the final error).

On RDC, I can see it created the folder my_project.git and it has a few files/folders, hooks, info, objects etc. Not touching it, just noting it.

Onto the local machine

I type exit, to exit the ssh

Like previous, I want these saved on the d drive. To avoid confusion, I'm going to call the parent directory repositories.

I'm currently in: /d/repositories

mkdir my_project
cd my_project
git init
-> Initialized empty Git repository in D:/repositories/my_project/.git/
(changed git add * to git add --all)
git add --all
git commit -m "my initial commit message"
>On branch master

Initial commit

nothing to commit

git remote add origin kannkor@1.1.1.1:d/repos/my_project.git
git push -u origin master
error: src refspec master does not match any.
error: failed to push some refs to 'kannkor@1.1.1.1:d/repos/my_project.git'

I believe this is because the initial commit didn't have anything. Still on the local machine, I navigate to: d:\\repositories\\my_project\\

I create a file: placeholder.txt, and add a single line of text, then save it.

Back to git bash

git add --all

git commit -m "my initial commit message"
[master (root-commit) ac54490] my initial commit message
 1 file changed, 1 insertion(+)
 create mode 100644 placeholder.txt

Much better for the local commit. I try the push again.

git push -u origin master
kannkor@1.1.1.1's password:
fatal: ''d/repos/my_project.git'' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

This is about where I have gotten stuck. My assumption, is this line:

git remote add origin kannkor@1.1.1.1:d/repos/my_project.git

I've tried many various ways, including:

git remote add origin kannkor@1.1.1.1:d:/repos/my_project.git

With \\ instead of /. Adding slashing to the end of it.

Few more various ones I attempted that all failed.

fatal: ''D:\repos\my_project.git'' does not appear to be a git repository
fatal: ''D:/repos/my_project.git'' does not appear to be a git repository

I also tried this, using the scp:

https://stackoverflow.com/a/20987150

Which ended in the same results.

Any advice would be appreciated.

d/repos/my_project.git does not look like a valid path.

/d/repos/my_project.git would.

Try:

git remote set-url origin kannkor@1.1.1.1:/d/repos/my_project.git
git push -u origin master

A little preliminary, but I do believe I have the answer/solution(work around).

https://github.com/PowerShell/Win32-OpenSSH/wiki/Setting-up-a-Git-server-on-Windows-using-Git-for-Windows-and-Win32_OpenSSH

In short, there is a known bug (been around since 2017), where when the default shell of the server is using cmd.exe, it is not consuming the single quotes. That's why the errors would come back with odd looking double single quotes.

fatal: ''D:\repos\my_project.git'' does not appear to be a git repository

The work around, is to change the default shell of the server, from cmd.exe to powershell. Details on doing this can be found here .

I'm copy/pasting the link above incase that link ever goes dead.

Before configuring DefaultShell, ensure the following prerequisites are met

OpenSSH installation path is in system PATH. If not already present, amend system PATH and restart sshd service.

Follow these steps:

On the server side, configure the default ssh shell in the windows registry. Computer\\HKEY_LOCAL_MACHINE\\SOFTWARE\\OpenSSH\\DefaultShell - full path of the shell executable

Computer\\HKEY_LOCAL_MACHINE\\SOFTWARE\\OpenSSH\\DefaultShellCommandOption (optional) - switch that the configured default shell requires to execute a command, immediately exit and return to the calling process. By default this is -c.

Powershell cmdlets to set powershell bash as default shell

New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value  C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -PropertyType String -Force  
New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShellCommandOption -Value  "/c" -PropertyType String -Force

To confirm you've done the above correct, when you ssh into the server, you should be in a powershell, instead of a cmd prompt.

And finally, the correct syntax for the commands, was indeed this:

kannkor@1.1.1.1:D:/repos/my_project.git

To kind of put it all together..

git remote add origin kannkor@1.1.1.1:D:/repos/my_project.git
git push origin master
kannkor@1.1.1.1's password:
Everything up-to-date

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM