Git Clone from Linux to Windows through Local Network
Earlier, I blogged about how to clone a Git repository from Windows to Linux through a local network. Now, I think it’s necessary that I should write something about the other way around, which is cloning a Git repository in a shared directory of a Linux machine to a machine using Windows. This is how to do it:
Step 1: Install the required software.
We need Samba to allow Windows machines to connect to our Linux shared directory.
sudo apt-get install samba
Step 2: Create Samba password.
When trying to open shared directories in Linux from a Windows machine, the user will be asked to provide a username and password to your Linux machine. For security reasons – I think! – Samba doesn’t use your original Linux password. Instead, you’ll have to create a “Samba Password” for the Linux user account that you’tr going to share with your co-workers, who are using Windows machines. That way, you don’t have to give them your actual password associated with that user account.
sudo smbpasswd -a YourUserName
Then the terminal will ask you to provide a new password as your Samba password.
Step 3: Make sure both Windows and Linux machine are in the same workgroup.
In you Windows machine, Right click on “My Computer” icon and choose “Propertise”. Then check what’s the name of the workgroup.
In Linux, do:
sudo gedit /etc/samba/smb.conf
and Gedit will open with the Samba configuration file. Look for “workgroup” and see what’s the specified workgroup name.
If the workgroup name from Windows and Linux don’t match, you’ll have to change either to match the other. If you changed the workgroup in Windows, you’ll have to restart your machine. If you changed the workgroup in Linux, you’ll have to restart your Samba server.
To restart Samba server, just issue following command in terminal:
sudo /etc/init.d/samba restart
If your workgroup names matches, you can proceed to next step.
Step 4: Share the directory that has Git repository.
You then have to share the directory that contains Git repository.
In your Linux machine, open your file manager and navigate to the parent directory of the directory that contains your Git repository. Right click on the directory with the Git repository and click “Propertise”. A properties window will be opened. In that window, go to “Permissions” tab. Make sure the user account, for which you created the Samba password earlier, is either the owner of that directory or, it is selected in the “Group:” dropdown list. To successfully clone, pull and push to your Git repository in Linux, from Windows, that user must have the “Folder Access:” selected as “Create and delete files”.
Once the required options are correctly selected, click “Apply Permissions to Enclosed Files”, and then close the window.
Step 5: Check if you can see your Linux machine from Windows.
In your Windows machine, go to “Network Locations” and check whether you can see your Linux machine there. If you can see, double click on it and, if everything went well, you’ll be able to see a list of shared directories from your Linux machine.
Double click on the directory you just shared and Windows will ask you to provide a username and a password. Provide Windows with your username and it’s Samba password. If everything went well, again, you’ll have access to your shared directory from Linux on your Windows machine.
Step 6: Copy the network location address of your Linux shared directory.
Imagine your Linux machine’s name is “MyLinuxMachine” and the shared name you gave for the directory you shared is “MySharedDirectory“.
Once you’re in the MySharedDirectory within Windows Explorer, copy the address of that directory. It’ll probably look like this:
Step 7: Clone the Git repository to Windows machine.
Go the location where you need the Git clone, and issue the following command in Git bash (or Windows Command Line, if you’ve properly set path to Git in Windows Environment Variables.).
git clone \\MyLinuxMachine\MySharedDirectory
Note that I have replace forward slashes in the address to shared directory with back slashes. The cloning won’t work otherwise.