You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

基于OpenSSH在Windows Server 2016上通过Git部署仓库遇阻

Troubleshooting Git Operations Between Ubuntu and Windows AD Server

Let's break down the potential issues and fixes step by step—great call confirming basic SSH connectivity works first, that eliminates a big chunk of possible problems!

1. Fix SSH Config Username Format

Your current .ssh/config has a redundant domain in the User field, which can cause subtle parsing issues with Git's remote URL handling:

Host INTRANET
    Hostname 192.168.1.153
    User git  # Changed from "git@INTRANET"
    IdentityFile ~/.ssh/id_rsa

Since INTRANET is already your AD domain, specifying just git as the user is sufficient. This ensures Git uses the correct git@INTRANET identity without redundant formatting that might confuse the remote server.

2. Verify Git Repository Path & Remote URL

When targeting the Windows bare repo, you need to use POSIX-style paths in the Git remote URL (thanks to Win32-OpenSSH translating paths):

  • If your Windows bare repo lives at C:\GitRepos\my-project.git, the SSH-accessible path becomes /c/GitRepos/my-project.git
  • Set your remote URL correctly from the Ubuntu repo:
    git remote add windows INTRANET:/c/GitRepos/my-project.git
    # Test directly with a push command first to rule out remote setup issues:
    git push INTRANET:/c/GitRepos/my-project.git master
    

If the repo is inside the git user's home directory (C:\Users\git\my-project.git), you can use a shorter relative path:

git remote add windows INTRANET:./my-project.git

3. Ensure Windows Repo is a Bare Repository

Git blocks pushes to non-bare repos by default (to avoid overwriting working directory changes). In your SSH session to Windows, verify the repo type:

cd /c/GitRepos/my-project.git
ls

You should see folders like objects, refs, and files like config—if you spot a .git folder instead, it's a regular repo. Fix this by either:

  • Reinitializing as bare (recommended for shared repos):
    # Backup the existing repo first!
    mv /c/GitRepos/my-project.git /c/GitRepos/my-project-backup
    git init --bare /c/GitRepos/my-project.git
    # Push from Ubuntu to populate the new bare repo
    
  • Or enabling pushes to non-bare repos (only for personal, non-shared use):
    cd /c/GitRepos/my-project.git
    git config receive.denyCurrentBranch updateInstead
    

4. Validate Git Installation & Permissions on Windows

Check Git Availability

In your SSH session to Windows, run:

git --version

If you get a "command not found" error, install Git on Windows and ensure it's added to the system PATH (not just the user PATH—Win32-OpenSSH runs in a system context, so user-only PATH entries won't be picked up).

Fix Directory Permissions

Ensure the INTRANET\git user has Full Control permissions on the Windows bare repo directory:

  1. On Windows Server, navigate to the repo folder in File Explorer
  2. Right-click → Properties → Security tab
  3. Add INTRANET\git to the permissions list
  4. Grant Full Control (at minimum, Read, Write, and Modify permissions)
  5. Check "Replace all child object permission entries with inheritable permission entries from this object" to apply permissions to all subfolders/files in the repo

5. Debug with Verbose Git Output

If you still hit roadblocks, run your Git command with verbose SSH output to get detailed logs:

GIT_SSH_COMMAND="ssh -v" git push windows master

This will show the full SSH handshake and Git remote interaction, which can pinpoint exactly where the process fails (e.g., authentication, path resolution, or remote Git errors).

内容的提问来源于stack exchange,提问作者Peter Peterson

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 04:28:58