Ubuntu 16.04连接Windows Git仓库:SMB协议不支持的解决方法
Alright, let's tackle this issue since Git doesn't natively support SMB URLs—here are two solid solutions you can try right away:
This works by mapping the SMB network share to a local directory on your Ubuntu 16.04 system, so Git can treat the repository like a local folder.
- First, install the SMB client utilities needed to mount the share:
sudo apt-get update && sudo apt-get install cifs-utils - Create a local directory to mount the share into (pick any path you prefer):
mkdir ~/windows-git-repos - Mount the SMB share. Replace
your-windows-usernameandyour-windows-passwordwith your actual credentials for the Windows machine. If the Windows machine is part of a domain, adddomain=your-domain-nameto the-ooptions:sudo mount -t cifs //192.168.1.71/users/Git ~/windows-git-repos -o username=your-windows-username,password=your-windows-password - Now update your Git remote to use the local mounted path:
git remote set-url origin ~/windows-git-repos/myrepo.git - You can now use standard Git commands (
git pull,git push, etc.) as you would with any local or remote repository.
Optional: To make the mount persistent across reboots, add this line to your /etc/fstab file (replace placeholders with your details):
//192.168.1.71/users/Git /home/your-ubuntu-username/windows-git-repos cifs username=your-windows-username,password=your-windows-password,uid=$(id -u),gid=$(id -g) 0 0
The uid and gid parameters ensure the mounted files have your Ubuntu user's permissions, avoiding permission issues.
If mounting the share long-term isn't ideal, you can configure the Windows machine to serve the Git repository over a protocol Git supports (SSH, HTTP/HTTPS).
Option 2.1: Use SSH
Most modern Windows versions (10+) have a built-in OpenSSH server, or you can use the one included with Git for Windows:
- On the Windows machine, enable the OpenSSH Server (Settings > Apps > Optional features > Add a feature > OpenSSH Server > Install). Start the service and set it to auto-start via Services.msc.
- Ensure the Windows firewall allows incoming connections on port 22 (the default SSH port).
- On your Ubuntu system, update the Git remote to use the SSH path. Note that Windows paths are converted to Unix-style (e.g.,
C:\users\Git\myrepo.gitbecomes/c/users/Git/myrepo.git):git remote set-url origin your-windows-username@192.168.1.71:/c/users/Git/myrepo.git - For convenience, set up SSH key authentication so you don't have to enter your password every time.
Option 2.2: Use HTTP/HTTPS
You can use tools like Gitblit, Gitea, or even IIS to host the repository over HTTP/HTTPS:
- Install a Git server tool on the Windows machine (Gitblit is lightweight and easy to set up).
- Add your
myrepo.gitrepository to the server. - Update your Git remote on Ubuntu to use the HTTP URL provided by the server, e.g.:
git remote set-url origin http://192.168.1.71/git/myrepo.git
- Verify your VPN connection is working: Ping
192.168.1.71from Ubuntu to ensure you can reach the Windows machine. - If you run into permission issues with the SMB mount, double-check the Windows user has read/write access to the
users/Gitdirectory.
内容的提问来源于stack exchange,提问作者Leevi L

