Hosting Git Repository in Windows - windows

Is there currently a way to host a shared Git repository in Windows? I understand that you can configure the Git service in Linux with:
git daemon
Is there a native Windows option, short of sharing folders, to host a Git service?
EDIT:
I am currently using the cygwin install of git to store and work with git repositories in Windows, but I would like to take the next step of hosting a repository with a service that can provide access to others.

Here are some steps you can follow to get the git daemon running under Windows:
(Prerequisites: A default Cygwin installation and a git client that supports git daemon)
Step 1: Open a bash shell
Step 2: In the directory /cygdrive/c/cygwin64/usr/local/bin/, create a file named "gitd" with the following content:
#!/bin/bash
/usr/bin/git daemon --reuseaddr --base-path=/git --export-all --verbose --enable=receive-pack
Step 3: Run the following cygrunsrv command from an elevated prompt (i.e. as admin) to install the script as a service (Note: assumes Cygwin is installed at C:\cygwin64):
cygrunsrv --install gitd \
--path c:/cygwin64/bin/bash.exe \
--args c:/cygwin64/usr/local/bin/gitd \
--desc "Git Daemon" \
--neverexits \
--shutdown
Step 4: Run the following command to start the service:
cygrunsrv --start gitd
You are done. If you want to test it, here is a quick and dirty script that shows that you can push over the git protocol to your local machine:
#!/bin/bash
echo "Creating main git repo ..."
mkdir -p /git/testapp.git
cd /git/testapp.git
git init --bare
touch git-daemon-export-ok
echo "Creating local repo ..."
cd
mkdir testapp
cd testapp
git init
echo "Creating test file ..."
touch testfile
git add -A
git commit -m 'Test message'
echo "Pushing master to main repo ..."
git push git://localhost/testapp.git master

GitStack might be your best choice. It is currently free (for up to 2 users) and open source at the time of writing.

Here's a dedicated git server for windows: https://github.com/jakubgarfield/Bonobo-Git-Server/wiki

If you are working in a Windows environment, have you considered Mercurial? It is a distributed version control system like Git, but integrates far more neatly and easily with Windows.

Installing CygWin is an overkill, read this tutorial on how to do it faster and native:
http://code.google.com/p/tortoisegit/wiki/HOWTO_CentralServerWindowsXP

If you get the error cygrunsrv: Error starting a service: QueryServiceStatus: Win32 error 1062: The service has not been started. after running the command:
cygrunsrv --start gitd
that means that you did not create the 'base-path' folder.
Creating the folder '/git' and rerunning the command will fix this.

I'm currently using cygwin's ssh daemon on Windows to serve up and allow remote access to my repo. It works quite well, I have complete control over who accesses my repo by their ssh certificates, and the performance blazes, even over remote WAN and VPN links.
Another solution is to use Gitosis. It is a tool that makes hosting repos much easier.

You do not need to host a service, you can also create a shared repository on a shared drive. Just create a bare repository. You can clone an existing repo into a shared one using: "git clone --bare --shared [source] [dest]". You can also init a new repository using "git init --bare --shared=all".
Henk

Have you considered using the cygwin layer? See this link.

Now msysGit supports git daemon ! It works fine (for me at least). I gonna try to make it run as service...

SCM Manager
Lightweight http-server for Git, Mercurial, Subversion repos from a box (only Java is needed)
Web-interface for management of users, ACLs, repos

On Windows, you can also serve Git repositories with Apache over HTTP or HTTPS, using the DAV extension.
The Git repository path can then be protected with Apache authentication checks such as restricting to certain IP addresses or htpasswd/htdigest type authentication.
The limitation of using htpasswd/htdigest authentication is that the username:password is passed in the requested Git URL, so restricting access to the Git URL to certain IP addresses is better.
Edit: Note, you can leave the password out of the Git URL and Git will prompt you for the password on push and fetch/pull instead.
Using HTTPS means all the data is encrypted in transfer.
It's easy enough to set up, and works.
The following example shows the combination of access control by IP address and user:password over standard HTTP.
Example Apache Virtualhost
## GIT HTTP DAV ##
<VirtualHost *:80>
ServerName git.example.com
DocumentRoot C:\webroot\htdocs\restricted\git
ErrorLog C:\webroot\apache\logs\error-git-webdav.log
<Location />
DAV on
# Restrict Access
AuthType Basic
AuthName "Restricted Area"
AuthUserFile "C:\webroot\apache\conf\git-htpasswd"
# To valid user
Require valid-user
# AND valid IP address
Order Deny,Allow
Deny from all
# Example IP 1
Allow from 203.22.56.67
# Example IP 2
Allow from 202.12.33.44
# Require both authentication checks to be satisfied
Satisfy all
</Location>
</VirtualHost>
Example .git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = http://username:password#git.example.com/codebase.git
[branch "master"]
remote = origin
merge = refs/heads/master

At work I'm using GitBlit GO installed on a Windows Server. Work flawlessly and integrate well with ActiveDirectory for user authentication and authorization. It is also free and opensource (Apache licensed)
GitBlit homepage
Only HTTP(S) access is supported, no SSH, but under Windows you shouldn't need anything more.

this is a 2015 answer to a question that is over 7 years old.
For $10 one time payment, from https://bitbucket.org/product/server, one can purchase a 64-bit Windows licence for up to 10 users.
Apparently 32-bit versions are only available via their archive.
Bitbucket Server was previously known as Stash.
Please note that i have not tried this version but $10 seems like a good deal; here i read that Atlassian gives the $10 to charity. FWIW

I think what Henk is saying is that you can create a shared repository on a drive and then copy it to some common location that both of you have access to. If there is some company server or something that you both have ssh access to, you can put the repository someplace where you can SCP it back to your own computer, and then pull from that. I did this for my self a little while, since I have two computers. It's a hassle, but it does work.

For Windows 7 x64 and Cygwin 1.7.9 I needed to use /usr/bin/gitd as the args argument of cygrunsrv
cygrunsrv --install gitd \
--path c:/cygwin/bin/bash.exe \
--args /usr/bin/gitd \
--desc "Git Daemon" \
--neverexits \
--shutdown
Also, I needed to run bash as an Administrator to install the service.

Related

Bash script to run git commands and automatically enter my username and password [duplicate]

Is it necessary to store the personal access token somewhere locally on the machine after generating it in GitHub?
If yes, is there any preferred way where it could be stored?
Half the point of passwords is that (ideally) you memorize them and the system hashes them, so therefore they're never stored anywhere in plain text.
Yet GitHub's personal access token system seems to basically force you to store the token in plain text?
First, a PAT (Personal Access Token) is not a simple password, but an equivalent that:
you can generate multiple time (for instance, one per machine from which you need to access GitHub repository)
you can revoke at any time (from the GitHub web interface), which makes that PAT obsolete, even if it lingers around on one of those machines.
That differs from your password, which is unique to your account, and cannot be easily changed without having to also modify it everywhere you happen to use it.
Since a PAT can be used in place of a password when performing Git operations over HTTPS with Git on the command line or the API, you can use a git credential helper to cache it securely.
On Windows, for instance, that would use the Windows Credential Manager, through the GCM -- Git Credential Manager -- for Windows, Mac or Linux:
git config --global credential.helper manager-core
# Git 2.39+
git config --global credential.helper manager
(manager-core is being replaced by/renamed as manager for Git 2.39+, Q4 2022)
The first time you are pushing to a repo, a popup will ask for your credentials: username and your PAT.
The next time, it won't ask, and reuse directly that PAT, which remains stored securely in your Credential Manager.
A similar idea applies for Mac with the OSX keychain, and Linux with the GNOME Keyring (in 2021, it would need a DBus session and libsecret), but in 2021, GCM-Core covers those use cases.
The idea remains: store the PAT in an encrypted credentials store.
As mentioned above, the more modern solution (Q4 2020) is Microsoft Git-Credential-Manager-Core, or, Q4 2022, Microsoft Git-Credential-Manager
git config --global credential.helper manager-core
# Git 2.39+:
git config --global credential.helper manager
Before Git 2.39 (Q4 2022), for Linux:
You need for that to install git-credential-manager-core, downloading its latest release, like gcmcore-linux_amd64.2.0.474.41365.deb
sudo dpkg -i <path-to-package>
git-credential-manager-core configure
Although, with GCM (Git-Credential-Manager-Core) on Linux, as noted by Mekky Mayata in the comments, you need to define a git config --global credential.credentialStore first.
See "Credential stores on Linux":
There are four options for storing credentials that Git Credential Manager (GCM) manages on Linux platforms:
freedesktop.org Secret Service API
GPG/pass compatible files
Git's built-in credential cache
Plaintext files
By default, GCM comes not configured.
You can select which credential store to use by setting the GCM_CREDENTIAL_STORE environment variable, or the credential.credentialStore Git configuration setting.
As noted by agent18 in the comments, using git-credential-libsecret after installing libsecret-1-0 and libsecret-1-dev is a good first step.
But, again, that should be now wrapped by credential-manager-core (before Git 2.39).
In my case, in Ubuntu, the accepted solution didn't work with a message like
git: 'credential-manager' is not a git command
but store instead of manager worked well:
git config --global credential.helper store
Alternatively, you can create a ~/.netrc file in home directory and save your login credentials to it.
cat ~/.netrc
machine github.com login <login-id> password <token-password>
Tested on Ubuntu 20.04, almost fresh install, with Git 2.25.1 and unity 7.5.
Authentication basics
Github needs an authentication key (with certain rights tied to said authentication key). A particular auth key has certain rights, (read private repos, read write public repos etc...) and "acts as a password" coupled with rights which can be revoked whenever the user wants.
Personal Access Token
We start with making a PAT. I.E., Settings --> Developer Settings--> Persaonl access tokens --> Generate new token --> Note --> set permissions (repo,repo_hook maybe) --> generate token
git push the repo and type the generated token(very long password) as password when asked.
Storing the password in different ways
Can be done in a file and then using xclip to bring it back to clipboard and paste it everytime (Screw this)
Cache with the help of git commands git config credential.helper cache <time-limit-of-cache>. But you still have to somehow clipboard the password after the timelimit.
Store it permanently in a file with git commands git config credential.helper store (don't use --global). This is NOT ENCRYPTED. You can open the file and read it. (e.g., If someone gets access to your laptop they can pretty much read the Password using a bootable USB (assuming your whole system is not encrypted)).
Or go the encryption route as per here. It is not complicated at all. 3 simple steps.
sudo apt-get install libsecret-1-0 libsecret-1-dev
sudo make --directory=/usr/share/doc/git/contrib/credential/libsecret
git config credential.helper /usr/share/doc/git/contrib/credential/libsecret/git-credential-libsecret
This allows to store the password/personal access token in an encrypted format. The git config file can be found in the .git/config file in your loca repo as shown here, if you ever need it.
P.S.
There are many places that suggest the use of Gnome-keyring but that is apparently deprecated.
Storing passwords/PATs for more than one account
This becomes tricky and it appears as #VonC suggests that we need a Git-Credential-Manager core (GCM core). This answer is enhanced based on my findings in this answer.
First install GCM core
Download latest .deb package
sudo dpkg -i <path-to-package>
git-credential-manager-core configure
git config --global credential.credentialStore secretservice as we use libsecret
Get latest git
In my case I had git 2.25 and got error error: unknown option 'show-scope'. It appears that GCM core is using higher git
(atleast 2.26).
So install the latest and greatest git as per here:
sudo add-apt-repository ppa:git-core/ppa
sudo apt-get update
apt list git # shows the latest git currently 2.31
sudo apt-get install git #or sudo apt-get upgrade
Update git remote path with username built in
GCM core needs this to identify the different accounts.:(
git remote set-url origin https://user1#github.com/user1/myRepo1.git
git remote set-url origin https://user2#github.com/user1/myRepo1.git
^^^^^
Your ~/.gitconfig file will thus have the following :
[credential]
helper = /usr/bin/git-credential-manager-core
credentialStore = secretservice
[credential "https://dev.azure.com"]
useHttpPath = true
To store your credentials in cache and avoid logging in every time you perform a git action, follow these steps:
Navigate to your local repository folder.
In the current folder's terminal: git config --global --replace-all credential.helper cache
Perform git push or git pull.
Login with username and access token (access token is your password). The token can be setup in GitHub and have access to repo, workflow, write:packages and delete:packages.
Repeat git push or any git action and you'll find that it doesn't ask for login credentials from now on.
I like to keep them encrypted within the repository and load them using .envrc (https://direnv.net/)
For doing this I use ssh-vault to encrypt the data using my ssh keys that GitHub already is exposing, for example:
echo MY_TOKEN="secret" | ssh-vault -u <github-user> create > my-encypted-vars.ssh
Then the content of .envrc looks something like this:
echo "Enter ssh key password"
context=$(ssh-vault view $HOME/projects/my-encrypted.ssh | tail -n +2)
export ${context}
This will decrypt the data in my-encrypted-vars.ssh file and set MY_TOKEN into my environment variables every time I cd into the project dir.
By doing this tokens/variables are stored "safely" and always ready to use as environment variables
try enabling this to help with persisting across push / pulls
git config credential.helper store
For ongoing cloning of repo / for macOS users / install iTerm2
https://iterm2.com/
Enable Toolbelt
Just click the snippet whenever you need it.
P.S. you are using oh-my-zsh, aren't you?
https://github.com/ohmyzsh/ohmyzsh
You can cache your credentials for a defined time using:
git config --global credential.helper cache
The default cache period is 900 sec (15 min) but can be changed with:
git config --global credential.helper 'cache --timeout=3600'
See the following Github page:
https://docs.github.com/en/github/using-git/caching-your-github-credentials-in-git
This is not a permanent store and as per other comments credentials should not be stored in plain text, which is a security risk. I use a password manager (https://bitwarden.com/) to store the PAT (Personal Access Token) then copy it in for the first use, where it is then cached. A PAT is required if you enable 2FA on your Github account.
Well, you have to save the token somewhere, when you don't want to type it each time your app asks for it :-)
A good solution is using environment variables, as already suggested in one comment.
But you still have to set the environment variable somewhere.
On Windows (which I'm using), you could use the dialog box in the system settings (I don't know if other operating systems have something similar).
I don't do this, I prefer a script in my project.
In a private project, you may commit this to source control, but this is a matter of preference.
In one of my personal projects, I'm calling the GitHub API as well, using a personal access token.
It's a command line app and the end user will save the token in a config file (which is OK).
But I need the token for development as well, because the project has integration tests where I'm calling the GitHub API.
And that project is public on GitHub, so I couldn't save the token in source control.
What I did is this:
I have a batch file (remember, I'm on Windows) called environment-variables.bat which sets all required environment variables including the access token
I'm calling this in my build script and in the batch file I'm using to run my tests
environment-variables.bat is ignored in source control
But in source control, there's environment-variables.bat.sample instead, which contains the same, but a fake token/password.
So I can just rename this file to environment-variables.bat, replace the fake password by the real one, and everything works.
This is not the perfect solution for all cases, though.
In my project, I have the problem that I need to use more tokens/passwords for more APIs in the future.
So the number of tokens in my environment-variables.bat will increase, making it difficult for potential contributors to actually execute all integration tests. And I still don't know how to deal with that.
In my use case, I store the PAT in a password manager, e.g. LastPass, KeePass, 1Password. When I need it in a Linux environment ( e.g. Docker ), I save the PAT in an environment variable and then use git's credential helper setting. For example:
git config --global credential.helper 'cache --timeout 600'
<< eof tr -d ' ' | git credential-cache store
protocol=https
host=github.com
username=nonce
password=${GITHUB_PAT}
eof
With a PAT the username can be anything except blank. Here's a gist that elaborates:
https://gist.github.com/rwcitek/da862e9e27cc28d3e96e62a2ca4b2b64
Use git insteadOf. Basically replace every https://github call with your access tokens + https://
git config --global url."https://<username>:<github-token>#github.com/".insteadOf "https://github.com/
Now every call to github will automatically be appended with your credentials.
I found this great answer in here.
Some more info about git insteadOf.
You can store the github https token using pass.
Two alternatives to map a git host to a pass entry:
bash script to map to the right pass entry:
#!/usr/bin/env bash
# assuming "get" action from git and a config like this
# git config --global credential.helper $XDG_BIN_HOME'/git_credentials_from_pass $#'
while IFS= read -r line
do
echo "$line"
if [[ "$line" =~ host=.*github.com.* ]]; then
echo "username=your_user_name"
echo "password=$(pass show token_github.com/your_username)"
#else ...
fi
done
Change your_username and token_github.com the way you set it up with pass insert.
This adds the token to pass without typing or pasting twice:
echo your_github_token | sed p | pass add token_github.com/your_username
Install pass-git-helper and:
git config --global credential.helper '!pass-git-helper $#'
pass-git-helper needs an ini-file to map between the git request and the pass entry.
${XDG_CONFIG_HOME}/pass-git-helper/git-pass-mapping.ini example:
[DEFAULT]
username_extractor=entry_name
[github.com*]
target=token_${host}/your_github_username
Basically I did this on my machine:
https://gist.github.com/bsara/5c4d90db3016814a3d2fe38d314f9c23
My profile script is slightly different than described:
env=~/.ssh/agent.env
agent_load_env () { test -f "$env" && . "$env" >| /dev/null ; }
agent_start () {
(umask 077; ssh-agent >| "$env")
. "$env" >| /dev/null ;
}
agent_load_env
# agent_run_state: 0=agent running w/ key; 1=agent w/o key; 2= agent not running
agent_run_state=$(ssh-add -l >| /dev/null 2>&1; echo $?)
if [ ! "$SSH_AUTH_SOCK" ] || [ $agent_run_state = 2 ]; then
agent_start
ssh-add
elif [ "$SSH_AUTH_SOCK" ] && [ $agent_run_state = 1 ]; then
ssh-add
fi
unset env
Install Git Credential Manager! https://github.com/GitCredentialManager/git-credential-manager . GCM supports caching as well as a variety of platform-specific credential stores that persist between sessions.
Even better: GCM supports user-friendly secure authentication to GitHub and GitLab via web browser with OAuth. This means you no longer even need to create personal access tokens. When you git push, simply follow a link to GitHub and authorize the app. Subsequent authentications require no interaction.
OAuth is more secure than personal access tokens, because the tokens have short expiry, refreshed when required using longer-lived refresh tokens.
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
sudo apt update
sudo apt install gh
gh auth login
it will ask to enter the protocol and token
Then I clones the repo again . Its not asking for token

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

Gitolite hook doesn't work

I've set a GIT server on Windows with Cygwin and gitolite as it's described in the article.
On a client Windows machine I use TortoiseGit.
Right after the setup everything works ok. I can clone gitolite-admin repository with TortoiseGit using my SSH key and see the repository content.
But right after I try to push a new content of /conf/gitolite.conf the server is not accessible anymore using my SSH key (it's removed from *authorised_keys* on the server by gitolite).
The new content of gitolite.conf (I would like to add new repository Project):
repo gitolite-admin
RW+ = alexey
repo Project
RW+ = alexey
repo testing
RW+ = #all
What's wrong with it?
The problem was in sshd service environment. See this link for details.
To fix the problem reinstall the service with proper PATH variable setting. To do this on Windows Server 2008 use:
cygrunsrv -R sshd
cygrunsrv -I sshd -d "CYGWIN sshd" -p /usr/sbin/sshd -a "-D" -y tcpip -u cyg_server -w {cyg_server_password} --env "PATH=/usr/local/bin:/usr/bin:/bin:/cygdrive/c/Windows/system32:/cygdrive/c/Windows:/cygdrive/c/Windows/System32/Wbem"
cygrunsrv -S sshd
If you don't remember cyg_server account password you can rerun ssh-host-config.
To restore access for your public key use:
gl-setup ~/YourKey.pub
After these you can access and modify your gitolite-admin repository remotely.

How to set up private git server on linux

I have tried following how-set-up-your-own-private-git-server-linux and private-remote-git-repositories-ubuntu-linode but I am still having problems.
My local environment is windows and my remote linux. I have a couple of questions:
In the first article it describes setting up a public ssh key for the server - I've never done this before and I'm not sure where to type the commands (not even sure whether local or remote!!): ssh myuser#server.com mkdir .ssh and scp ~/.ssh/id_rsa.pub myuser#server.com:.ssh/authorized_keys
On my local dev machine should I be running msysgit? Is there an alternative because the version I installed is taking up 1.4 GB! I installed msysGit-netinstall-1.7.4-preview20110204.exe from http://code.google.com/p/msysgit/downloads/list
I tried skipping making the git user and public key, created the repositories on the remote machine but then when I try git remote add origin ssh://[username]#[domain/ip/hostname]/srv/git/[project-name] as root user it says: fatal: Not a git repository (or any of the parent directories): .git
I'm not sure if this should be here or if it would be best migrated over to a different site, but since I might be able to help I'll go ahead and answer.
I just skimmed the articles you linked. It looks like they both deal with accessing a git server over ssh, which you mention, so that's what I'll focus on.
First, on your server:
You need to set up an account on the server so that you can log in. This can be either a generic git account, or your own personal account. For the moment we'll assume that you are setting it up to work with a personal account. What you want to do is create your account, then somewhere accessible to that account (say, in your home directory), create the git repository.
mkdir myrepo.git
cd myrepo.git
git --bare init --shared=all
So now you have a git repository up on the server. Depending on the git client you are using, you might not need to mess with keys right now. If SSH is configured on your server to allow password login then you can probably just connect and enter your password when you need to interact with the server. If you want to set up keys, what you need to do is to generate an ssh public key. I don't know off hand how to do this in windows, but in linux you'd do something like:
ssh-keygen -t rsa -b 1024
That command will generate two files, "id_rsa" and "id_rsa.pub"; whatever tool you use should also generate two files, a public key and a private key. They might have different names, but assume for now that "id_rsa.pub" is the name of your public key file.
You want to copy the public key to the server, you can use scp, ftp, or just move it over using a thumbdrive. Either way, once you get it onto the server, and it's accessible by your user, log in as your user on the server. You want to add the public key to your "authorized_hosts" file, so after logging in to your account on the server, do this:
cd
mkdir .ssh
cat id_rsa.pub >> .ssh/authorized_hosts
rm id_rsa.pub
Now, from your workstation you need to configure your ssh client to use the private key your generated. Again, I don't know how to do this on Windows and it will probably vary depending on what ssh client you are using, so you'll need to get that information somewhere else.
Next, you need to create your local repository, add some files, and make a commit. Note that you can't clone the remote repository you made yet because there's nothing in there. Once you have some commits made locally, you need to set the remote server in your repository.
If you are using the git command line tools, you can run:
git remote add origin user#yourserver:myrepo.git
If you put the repository somewhere other than your home directory, use the full path:
git remote add origin user#yourserver:/path/to/repo.git
Note that you need the ".git" in there, since your directory name has ".git" as part of the name.
If you are using a GUI tool, then you instead just edit the configuration file for the repository. This will be in the top level of your repository under ".git/config". You'll want to add something like
[remote "origin"]
url = user#yourserver:/path/to/repo.git
fetch = +refs/heads/*:refs/remotes/origin/*
Now that your remote is configured, and you have some commits locally, you can push your master branch up to the server. If you're using the command line use:
git push origin master
Or, if you're working on a different branch:
git push origin mybranch
If you are using a GUI frontend for get then you'll need to look up the documentation for that tool on how to push.
I would like to recommend to use Gitolite that allows to setup git hosting on central srever with great features like access control and creating/managin repositories etc.
And for windows, the tool called git-scm can be used for setting up git client and also have GUI panel for git repositories. After installation of this git tool, you will get a git bash tool and a git GUI.
Gitolite makes settting up of a git hosting server and client very simple.
I hope this may help new people who are looking for an efficient solution for settting up git hosting server and clients in some easy to understand simple steps.
I followed the most voted answer and I didnt get it to work. I found this tutorial:
https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys--2
and I got it working. I think the problem was that, in the server, the public key is to be copied to a file "authorized_keys" and not "authorized_hosts".
I had been trying to generate the key pairs using putty but couldn't get it to work. In the end I realised that I could generate the keys via the msysgit command line using ssh-keygen -C "git#example.com" -t rsa. Copy the public key to the server using nano /home/git/.ssh/authorized_keys and hey presto!
I had downloaded the full source code hence the size! The non-source app, Git-1.7.4-preview20110204.exe was just 13MB via http://code.google.com/p/msysgit/downloads/list?can=3

How to stop git via ssh on windows from resolving the wrong path?

I have a windows 2003 box with an ssh server setup. I have msysgit (git version 1.6.2) installed both locally and on the server.
The server has the following absolute path to my repos:
e:\vc\git\myrepo.git
when a user logs in he/she will be put in the following working directory:
e:\vc\git\
When running the following cmd on my dev machine:
git clone ssh://myuser#myip/myrepo.git testrepo
I get the following error:
fatal: ''/myrepo.git'' does not appear to be a git repository
According to my ssh logs it appears that git is executing this cmd on the server:
'cmd.exe /c git-upload-pack '/myrepo.git''
Executing that command locally (on the server) fails for the same reason. I'm thinking the problem is related to git prefixing the path with a '/'. How do I tell git not to do this? Should this be working?
Note: git-upload-pack is working because I added \gitinstallpath\libexec\git-core to the path. Apparently this is a bug and will be fixed in the future, this was my work around.
I resolved this by switching my ssh server from winssh to openssh (via the cygwin layer). I was able to connect fine (as noted above) using winsshd, but winsshd wasn't correctly handling paths prefixed with "/". I could probably get winsshd to work, but switching to cygwin and openssh was faster.
Here's a good blog post to kick start the setup if your in a similar situation:
Have you tried the following?
git clone ssh://myuser#myip/myrepo testrepo
Note the removal of ".git" from the end of the SSH path. You only need that suffix at the end if the remote directory name has it.
Also, have you tried any other SSH URL format? To use a relative path, you can try:
git clone ssh://myuser#myip/~/myrepo testrepo
See the git clone man page for details on other URL formats.
If somebody still interested in workaround:
The problem is - cmd.exe doesn't understand single-quoted parameters. So we use sh instead.
Create file gup.sh with line
git-upload-pack.exe $*
and grp.sh with
git-receive-pack.exe $*
on server!
Then run:
git clone -u 'sh gup.sh' ssh://myuser#myip/e/vc/git/myrepo.git testrepo
git config remote.origin.uploadpack 'sh gup.sh'
git config remote.origin.receivepack 'sh grp.sh'

Resources