Git and SSH - How to know what address to use? - windows

I need to set up a git repository in the production server so I can upload all my commits. So, these are the steps I followed:
Production Server (Windows Server 2008)
Installed Git
Created an empty repository at inetpub/wwwroot
Installed CopSSH
Created a new user account
Enabled the user with CopSSH
Changed the default directory of the new user to the repository address
Setted environment variables to read Git commands
Development (Windows 7 + Netbeans)
Installed Git
Created a repository right where my project is
Added all files of the project to the repository
Now, I need to upload my dev project to prod. First, I'm checking if the SSH default directory where I'm pointing to is a repository:
$ git ls-remote ssh://user#server/
fatal: '/' 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.
I tried adding the folder name, ".git", foldername.git, everything, and I get the same error.
Where am I having the issue? Thank you beforehand.
P.S. I already tested the new default directory and it points right to the empty repository in the server, so it's working.
EDIT: I tried this:
$ git ls-remote user#host:.git
user#host's password:
$_
I got no output. Is that okay?

You're saying the git repository at your server is located at / (say, you should have a /.git directory). As that's probably not true, I'd suggest you to connect via ssh to the server and run pwd (or it's Windows equivalent) to found where your home directory is, and then get the relative path to your repository.
Say, if running pwd right after logging into the server gives you C:\users\my_user and your git repository is at C:\users\my_user\git\my_project, use ssh://user#server:git/my_project as the URL. The : means a relative path from your home directory.
Also you can use an absolute path, as in ssh://user#server/c/users/my_user/git/my_project, or however Windows decides to name your C: partition :)

As you use ssh transport, your syntax tries to access the root of your Copssh installation, Example: if you installed Copssh at c:\copssh, then your root (/) is the same directory.
Your command git ls-remote ssh://user#server/ tries to access that directory.
Try something like
git ls-remote ssh://user#server/home/user* (c:\copssh\home\user) or
git ls-remote ssh://user#server/cygdrive/d/mygit if your repository is at d:\mygit)
If you all want to create a Windows based Git repository, you may consider to stick with Gitwin which has a fully functional free edition. It is Git on Cygwin though and Disclaimer: I'm the developer.

Related

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

git clone from bare repository

I created a Visual Studio project using git, later I created a remote bare repository in the path \\xxx.yyy.com\dfs\CORP\Wkg\MoDat\tmp\avl\Repository\WCF\MIlib and added it as origin in Visual Studio, then pushed.
Remote repository seems to be up to date, and from command line a git remote -v in the local folder returns these 2 lines
origin \corp.repower.com\dfs\CORP\Wkg\MoDat\tmp\avl\Repository\WCF\MIlib (fetch)
origin \corp.repower.com\dfs\CORP\Wkg\MoDat\tmp\avl\Repository\WCF\MIlib (push)
I assume I can clone to another local folder from the remote path, so I just copied and pasted exactly the line above to clone it elsewhere
git clone "\\xxx.yyy.com\dfs\CORP\Wkg\MoDat\tmp\avl\Repository\WCF\MIlib" .
Now I get an error
git : Cloning into '.'...
fatal: '\xxx.yyy.com\dfs\CORP\Wkg\MoDat\tmp\avl\Repository\WCF\MIlib' 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.
I am cloning in the same system in another folder using the same (administrator) user, so it's definitly not relate to access right.
I see in the error that a \ is missing, am I doing something wrong? should the path be somehow escaped?
Are you writing these commands in some kind of bash?
When I was working on Windows I always used forward slashes / instead of backslashes. See if it works for you.

Jenkins configuration of git plugin

I get this error when configuring git repo in a new jenkins project:
Failed to connect to repository : Error performing command: ls-remote -h file:///c:\Dev\git\rx HEAD
I have a local git repo on my windows machine and cloning the same path from command prompt works on the same machine. I don't know what could be the problem (git.exe is on system path)
Windows installs Jenkins as a service. But it runs the Jenkins service under different user permissions that don't have access to GIT. You can follow this link to find the user that Jenkins runs under. http://antagonisticpleiotropy.blogspot.com/2012/08/running-jenkins-in-windows-with-regular.html
For example. My local user name on my windows is "nathandrewsire", exclude the quotes. Open windows services manager (either cmd and c:\services.msc, OR use windows key + R). Enable Log On > This account:. Then type in .\username (e.g. .\nathandrewsire). Then restart the service and you will have access to GIT from Jenkins builds.
I also found a snippet for windows shell command that will output the user to verify it.
echo %PATH%
echo %USERDOMAIN%\%USERNAME%
http://antagonisticpleiotropy.blogspot.com/2012/08/running-jenkins-in-windows-with-regular.html
Linux
If you're using Linux, this error can also be caused from not enabling share on your Git repo. Linux jenkins user won't be able to access Git report under another user unless....
git --bare init --shared=group
Also, your jenkins user and Git repo user must belong to the same group for file permission access. There's other alternatives to that like messing with umasks and ACL's but setting up a linux group for your two users is the easiest way.
Make sure NOT TO OVERWRITE your Git repo with the bare init command. If you already have a Git repo, you'll need to setup/move to a new one with the shared option. I didn't see a way to convert existing repos to shared because I am guessing the files would all need to be updated?
NOTE***
I used VMWare Workstation shared folders to build on a windows guest. Jenkins needs the following format when entering the Git repo.
//vmware-host/Shared Folders/vm-share/ridcyDevelopment.git/
Unable to get Jenkins and Git to play nice

Setting up a Git repository under Review-Board on Windows Server 2003

I need some help.
I have a Windows Server 2003 computer that I'm setting up with Git and Review-Board.
My Git repositories are managed by Gitolite. The setup is successful and everything is working fine (tested with multiple workstations).
The Review-Board site has installed successfully and is hosted under Apache 2.2. This is also working fine in itself (the website is accessible and responds for workstations), except the part where I'm trying to link Git repositories to Review-Board.
Most tutorials (example: http://ericholscher.com/blog/2011/jan/24/using-reviewboard-git/) provide good details on how to setup a Git repository under Review-Board, except that they refer to Linux/Unix systems, and I am running Windows Server 2003.
My Gitolite repositories are stored under D:\Repositories\Git
Example: D:\Repositories\Git\sdu-test\.git
My understanding is that Review-Board needs a local clone of the repository(ies). Therefore, I created a directory named LocalClones and I cloned my repository.
Example: D:\Repositories\LocalClones\[I cloned sdu-test.git here]
Command used (from LocalClones directory): git clone ../Git/sdu-test.git(the clone was successful)
Now, in Review-Board, I'm trying to declare my sdu-test repository.
Name is 'sdu-test'
Hosting type is 'Custom'
Repository type is 'Git'
Path is 'D:\Repository\LocalClones\sdu-test' (I have also tried with 'sdu-test.git', and 'sdu-test/.git')
Mirror path is 'ssh://git#localhost/sdu-test' (I have also tried simply 'git#localhost:sdu-test', and no mirror path at all)
When I click Save, I get the following error: (11001, 'getaddrinfo failed'). I have no idea what to do about that.
If I try to change the path to a Unix-style path ('/D/Repository/LocalClones/sdu-test'), I get a different error message: Permission denied accessing the local Git repository '/D/Repository/LocalClones/sdu-test'. With a Unix-style path, I could even write a directory path that doesn't exist ('/I/Dont/Exist') and the same permission denied error is returned (the path in the error message does reflect the change though).
Can anyone help me out and tell me how to declare my local Git repository in Review-Board under Windows?
Thank you very much!
** UPDATE ** thank you Tamagochi and VonC for your answers, but unfortunately they're not working for me. Even after fixing the git.py file, I still get the Permission denied accessing the local Git repository '/D/Repository/LocalClones/sdu-test' error message.
There appears to be a bug in ReviewBoard 1.5.5 that causes this error. You can resolve this problem in either of two ways:
Move your repositories to drive C.
Edit \reviewboard\scmtools\git.py file, and replace the following line:
self.git_dir = url_parts[2]
with:
self.git_dir = url_parts[1] + url_parts[2]
Then use the following path: file://D:/Repository/LocalClones/sdu-test
I don't have any experience with ReviewBoard, but from what I can gather (from your link):
you do need to put the full path up to the .git directory of the local clone.
you should make your local clone through an url-based address. If the local file protocol is to be used, you should try with file///D/Repository/LocalClones/sdu-test.
git#localhost:sdu-test would only work if you have a git daemon running.
ssh://git#localhost/sdu-test would only work if you have a ssh daemon running.

How to git clone a repo in windows from other pc within the LAN?

I have this git repo "c:/xampp/htdocs/**" in my main PC and its IP address is 192.168.0.6. Now I want to git clone this repo from ubuntu-server which running on a Vmware Player in my main PC.
I did
git clone \\192.168.0.6\c:\xampp\htdocs\****
and
git clone //192.168.0.6/c:/xampp/htdocs/****
from ubuntu-server and neither worked.
fatal: could not create work tree dir '****'.: Permission denied
What did I wrong?
what should I do?
You should use the command git daemon to host your repo, like this:
In your computer that will act as a server:
git daemon --base-path=<path_to_folder_containing_project_folder> --export-all
(please note that path_to_folder_containing_project is the folder containing your projects folders, it will provide all projects under that folder)
In your client:
git clone git://<local ip>/<project name>
The cloned repo will have its origin pointing to the server in your LAN, so you may want to use git remote set-url origin to point it to the original origin.
You may want to run git daemon with the --verbose option to get more details in case you run into problems.
Make sure that your c:/xampp/htdocs folder (or sub folders of it) is shared in windows, so you can navigate on the network by this address:
\\192.168.0.6\htdocs
Then you clone by using file:////. Note that there are four slashes:
git clone file:////192.168.0.6/htdocs/somerepo.git
To access the repo, you must either share it on 192.168.0.6 or must be the same domain user as the one that owns the file on 192.168.0.6.
If you share the directory on 192.168.0.6 (e.g. with share name myrepo), you access it with //192.168.0.6/myrepo.
If you are logged in on your box with a user accout that is known on 192.168.0.6, you could try accessing the repo through the administrative shares:
//192.168.0.6/c$/xampp/htdocs/...
Always use forward slashes.
Another alternative would be using SSH to access the remote machine.
Using explorer (smb) to mount the remote repository as a network share is the easiest way. I'm not entirely sure, but I think you paths might be wrong. Try file:///192.168.0.6\c:\xampp... instead.
There are two things that might have gone wrong for you:
You don't have read permission on the remote repository
You don't have write permission in the location you want to create your repository ( the current working directory or the directory you specify as second argument to git clone)
And also check if your samba server works for normal file access.
To make git repo on Windows local network you'd need to do the following:
Create new repo
git init --bare projectName.git
Share this folder (projectName.git) with the users you need
Find your PC ip with ipconfig command (e.g. 192.168.2.101)
Run this command from some user's machine
git clone //192.168.2.101/projectName.git
Note: open \\192.168.2.101 in finder to see the correct path to the projectName.git (e.g. //192.168.2.101/some/path/projectName.git)
I recently ran into this error while trying to clone a repository in a remote pc to a local pc within the same LAN network.
The solution was to first make sure the drive location in the remote pc had the correct access rights for the local PC(Read/Write-which can be set using windows sharing options)
Copy the path of the remote repository. In your local pc paste the path in a windows explorer window. Then copy its directory address and paste it into any browser.
Now you should get a link with the hostname and the correct cloning URL format.
Use this link to clone the repository in the local pc.
Hope this helps.
Cheers.
"I have a few different computers that I use at home and I wanted to set up GIT that I can access my code from any of them. It took me a bit because I was too used to working with a client-server model where I designate one machine as the "server" that holds the repository and everything else was a client. Instead, GIT seems to operate more like a merge tool and every local copy is its own "master." Once I understood that, it turns out that setting up GIT is very simple and just needs GIT itself and SSH".
To read more you can check this link:
http://blog.lazyhacker.com/2010/04/setting-up-git-for-home-network.html

Resources