Working on a project at Sanmark Solutions, I encountered a situation where I needed to clone a Git repository placed in a shared directory in a Windows machine into a working directory in a Linux machine. First I tried to do it with SSH, but I wasn’t successful. I guess that’s because I am not much experienced with that protocol. Then I decided to access the directory in Windows with Samba and mount it on local file system, and then clone, pull, and push from and to it considering it as a local location. This is how I did it:
Step 1: Install the required software.
We need Samba to connect to Windows shared directories.
sudo apt-get install samba sudo apt-get install system-config-samba
Step 2: Create a mount point.
We need a place in our file system to mount the Windows directory.
sudo mkdir /mnt/directory_from_windows
Step 3: Mount the directory from Windows onto the created mount point.
We need to be able to access the directory from Windows through our mount point.
sudo mount -t cifs -o username=WindowsUsername,password=WindowsPassword //IPAddressToWindowsMachine/SharedDirectoryFromWindows /mnt/directory_from_windows
Here are what various flags to mount application in above command mean (Extracted from man pages.):
-t, --types
“The argument following the -t is used to indicate the file system type.”. So CIFS is the file system types used here.
-o, --options
“Options are specified with a -o flag followed by a comma separated string of options.”. We use the options username and password here.
Step 4: Verify the Windows shared directory is successfully mounted.
Do
cd /mnt/directory_from_windows ls
and check whether you can see files from your Windows shared directory. If that works, you can go clone your Git repository, if not, you’ll have to troubleshoot.
Step 5: Clone your Git repository.
Go to the place where you need to create your working copy of the Git repository. In this example, I am assuming it’s your home directory.
cd ~
Then issue the command to perform the clone.
git clone /mnt/directory_from_windows
Voila!
Bonus Step: Unmount mounted Windows shared directory.
If you need to unmount your mounted Windows shared directory, do:
sudo umount -a -t cifs -l
12 responses to “Git Clone from Windows to Linux through Local Network”
This is very useful. I have found myself in the position needing to mount windows on a linux machine with Samba and this is not obvious! Thanks!
Really good guide i’ve been trying to solve this for a long time thanks for the information I’ll give it a go and probably be back with questions when i get stuck …hope not though.
Thank you so much for sharing this! Logical and informative!
Very useful program
Soldi information! Thanks
Moving away from Windows has been impossible for compatibility issues. However, this product is a step in the right direction as it makes a Linux box a real possibility without having to worry about compatibility.
quality info, thanks!
Excellent technical advice worth sharing. Thank you very much.
Interesting although I more typically am trying to access files on a Linux box from a Windows client. Good info.
Thanks, wasn’t aware of this installation
This setup works pretty good, but how to push changes, when I tried to do this it gave me this:
Counting objects: 119, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (109/109), done.
remote: fatal: Unable to create temporary file ‘/mnt/directory_from_windows/objects/pack/tmp_pack_XXXXXX’: Permission denied
error: pack-objects died of signal 13
error: failed to push some refs to ‘/mnt/directory_from_windows’
Ok I got the solution this was, because, the mounted directory is owned by root user and I was pushing changes as a normal user. Thanks a lot this tutorial for git clone from windows to linux pc on LAN is very very useful