Introduction

First of all, let me clarify that Git doesn’t need to specify the side for client and server. Your workstation can be both the client and server. That means you can get code from other computer, you’re the client; while others can also get code from your computer, you’re the server. That’s why Git is great.

In this post, the “Git server” means to make your computer available for others to pull/push code from/to.

The post is long because it’s step by step and with lots of screenshots. In fact, it just takes about 10 minutes to setup all.

Note: CopSSH is not open source any more, please buy it if you want to use it.

Software Requirement

Software required to setup a Git server:

  • CopSSH (install on the server side)

  • msysgit (install both on the server side and client side)

  • PuTTY (install both on the server side and client side)

Software required to integrate with Visual Studio:

  • GitExtensions (install both on the server side and client side)

Setup Steps

1. Install msysgit

  1. When you installing the msysgit, please choose c:\Git as the installation directory, because the space in the directory name may cause an issue in bash commands.

Step by Step Setup Git Server on Windows with CopSSH + msysGit and Integrate Git with Visual Studio_第1张图片

In the “Adjusting your PATH environment”, I recommend to select “Use Git Bash only”.

Step by Step Setup Git Server on Windows with CopSSH + msysGit and Integrate Git with Visual Studio_第2张图片

Other settings are default. After installation, you get the git bash icons on your desktop. You can try it with git command, if you get the following screen, you’ve installed the msysgit successfully.

Step by Step Setup Git Server on Windows with CopSSH + msysGit and Integrate Git with Visual Studio_第3张图片

Add C:\Git\bin and C:\Git\libexec\git-core to Path. This step is very important.

Step by Step Setup Git Server on Windows with CopSSH + msysGit and Integrate Git with Visual Studio_第4张图片

2. Install CopSSH

  1. Just like the msysgit, we don’t install the CopSSH in program files folder to avoid some space issues. We install it to c:\ICW.

Step by Step Setup Git Server on Windows with CopSSH + msysGit and Integrate Git with Visual Studio_第5张图片

2. Install CopSSH

  1. Just like the msysgit, we don’t install the CopSSH in program files folder to avoid some space issues. We install it to c:\ICW.

    Step by Step Setup Git Server on Windows with CopSSH + msysGit and Integrate Git with Visual Studio_第6张图片


  2. Just use the default account as CopSSH provides:

    Step by Step Setup Git Server on Windows with CopSSH + msysGit and Integrate Git with Visual Studio_第7张图片


  3. After installation, open COPSSH Control Panel.

    Step by Step Setup Git Server on Windows with CopSSH + msysGit and Integrate Git with Visual Studio_第8张图片


  4. Click Add button in Users tab.

    Step by Step Setup Git Server on Windows with CopSSH + msysGit and Integrate Git with Visual Studio_第9张图片


  5. Choose an existing user on your computer (you can create one in computer management). Here in my sample, the user is jinweijie.


    Step by Step Setup Git Server on Windows with CopSSH + msysGit and Integrate Git with Visual Studio_第10张图片

  6. Allow all access:

    Step by Step Setup Git Server on Windows with CopSSH + msysGit and Integrate Git with Visual Studio_第11张图片


  7. After the user is activated, click the Keys… button in the Activated Users section:

    Step by Step Setup Git Server on Windows with CopSSH + msysGit and Integrate Git with Visual Studio_第12张图片


  8. Click Add:

    Step by Step Setup Git Server on Windows with CopSSH + msysGit and Integrate Git with Visual Studio_第13张图片


  9. Use default key settings:

    Step by Step Setup Git Server on Windows with CopSSH + msysGit and Integrate Git with Visual Studio_第14张图片


  10. Enter the Passphrase and File name:

    Step by Step Setup Git Server on Windows with CopSSH + msysGit and Integrate Git with Visual Studio_第15张图片


  11. The private key will be saved to c:\ICW\home\jinweijie\ryan-vm-01_2048.ppk.

    Step by Step Setup Git Server on Windows with CopSSH + msysGit and Integrate Git with Visual Studio_第16张图片


[Test step] Now we try to use the activated user to log on through SSH, open Git Bash, enter commands:

ssh jinweijie@ryan-vm-01

Enter “yes” to continue.

Step by Step Setup Git Server on Windows with CopSSH + msysGit and Integrate Git with Visual Studio_第17张图片

[Test step] After entering your passwords (the windows account’s password), then you try to run git as the ssh user, but it isn’t performed as you expected:

Step by Step Setup Git Server on Windows with CopSSH + msysGit and Integrate Git with Visual Studio_第18张图片

That’s because CopSSH cannot find the git.exe on the server, so we need to tell CopSSH the git path.

3. Config CopSSH with Git path.

  1. Open C:\ICW\etc\profile with your favorite editor, add :/cygdrive/c/git/bin:/cygdrive/c/git/libexec/git-core(don’t forget the starting colon) to PATH , the whole line will be:

    export PATH="/bin:$syspath:$winpath:/cygdrive/c/git/bin:/cygdrive/c/
    		git/libexec/git-core" 

    Then Save.

    Step by Step Setup Git Server on Windows with CopSSH + msysGit and Integrate Git with Visual Studio_第19张图片


  2. Restart the CopSSH by clicking twice the big button in CopSSH Control Panel:

    Step by Step Setup Git Server on Windows with CopSSH + msysGit and Integrate Git with Visual Studio_第20张图片


  3. If we run Git Bash again, ssh jinweijie@ryan-vm-01, enter your password and run the git command, git should be found this time:

    Step by Step Setup Git Server on Windows with CopSSH + msysGit and Integrate Git with Visual Studio_第21张图片


4. Configure Private Key on Client

  1. Copy the private key (we generated in step 1-k) from server to client.

    Step by Step Setup Git Server on Windows with CopSSH + msysGit and Integrate Git with Visual Studio_第22张图片


  2. On the client side, use puttygen.exe to load the key (if you set the password in 1-j, you need to enter the password while loading the key):

    Step by Step Setup Git Server on Windows with CopSSH + msysGit and Integrate Git with Visual Studio_第23张图片


  3. Click “Save private key” to save a copy of private key for plink.exe to recognize.

    Step by Step Setup Git Server on Windows with CopSSH + msysGit and Integrate Git with Visual Studio_第24张图片


5. Create Repository, Integrate with Visual Studio

  1. Install gitextensions on both server and client.

    Step by Step Setup Git Server on Windows with CopSSH + msysGit and Integrate Git with Visual Studio_第25张图片


  2. Since we have already installed the msysgit in step 1-a, we skip the “Install MsysGit”. But if you haven’t install msysgit on the client machine, you can check the checkbox and install it.

    Step by Step Setup Git Server on Windows with CopSSH + msysGit and Integrate Git with Visual Studio_第26张图片


  3. Install to C:\GitExtensions\, other settings are default.

    Step by Step Setup Git Server on Windows with CopSSH + msysGit and Integrate Git with Visual Studio_第27张图片


  4. On the server side, open Git Extensions, click “Create new repository”.

    Step by Step Setup Git Server on Windows with CopSSH + msysGit and Integrate Git with Visual Studio_第28张图片


  5. On the server side, set the path to the project name under you CopSSH user’s home directory, select“Central repository, no working dir” (because we are the server), then “Initialize”:

    Step by Step Setup Git Server on Windows with CopSSH + msysGit and Integrate Git with Visual Studio_第29张图片


  6. On the client side, open Git Extensions, click “Clone repository”:

    Step by Step Setup Git Server on Windows with CopSSH + msysGit and Integrate Git with Visual Studio_第30张图片


  7. On the client side, the repository address should be ssh://jinweijie@ryan-vm-01/ICW/home/jinweijie/mydotnetproject. Please be aware that, the repository should begin with c:\ on the server.

    Step by Step Setup Git Server on Windows with CopSSH + msysGit and Integrate Git with Visual Studio_第31张图片


  8. On the client side, click “Load SSH Key” and load the key which was saved in step 4-b:

    Step by Step Setup Git Server on Windows with CopSSH + msysGit and Integrate Git with Visual Studio_第32张图片


  9. On the client side, enter the password if you set password to the key, then click Clone:

    Step by Step Setup Git Server on Windows with CopSSH + msysGit and Integrate Git with Visual Studio_第33张图片


  10. On the client side, add ignore files:

    Step by Step Setup Git Server on Windows with CopSSH + msysGit and Integrate Git with Visual Studio_第34张图片


  11. On the client side, open Visual Studio, create a project to mydotnetproject folder (which is the cloned repository), you may find the files are already under git source control:

    Step by Step Setup Git Server on Windows with CopSSH + msysGit and Integrate Git with Visual Studio_第35张图片


  12. Click the “Commit” button on the menu bar, then click “Commit & Push”:

    Step by Step Setup Git Server on Windows with CopSSH + msysGit and Integrate Git with Visual Studio_第36张图片


  13. Push succeeded:

    Step by Step Setup Git Server on Windows with CopSSH + msysGit and Integrate Git with Visual Studio_第37张图片


  14. On the server side, you can find the new pushed files:

    Step by Step Setup Git Server on Windows with CopSSH + msysGit and Integrate Git with Visual Studio_第38张图片


That’s all, happy GITTING! :)

参考:

http://www.codeproject.com/Articles/296398/Step-by-Step-Setup-Git-Server-on-Windows-with-CopS

https://code.google.com/p/gitextensions/downloads/list

http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

https://code.google.com/p/msysgit/downloads/detail?name=msysGit-fullinstall-1.8.4-preview20130916.exe&can=2&q=

https://www.itefix.no/i2/content/copssh-free-edition

http://wenku.baidu.com/view/f421c5ebe009581b6bd9eb6d.html

http://www.cnblogs.com/kysnail/archive/2012/03/16/2399589.html

http://www.weste.net/2013/1-31/88703.html

http://www.weste.net/2013/1-31/88703.html

http://book.51cto.com/art/201107/278854.htm

http://www.lifeba.org/arch/git_gitosis.html

http://blog.sina.com.cn/s/blog_67a3453d0101j8qr.html