Next time you need to transfer a file between computers and are about to reach for a USB flash drive, think about the following two cases. If either of them matches, you have an alternative! As icing on the cake, you can use either method whether you are on a Linux, Mac, or Windows-based system.
Case 1: The folder you want to share is under git control (aka "using git daemon")
Git is a powerful source control management tool. If you want to share your local repository to your colleagues or friends, you can use the git-daemon command. Suppose I have three projects in my "git" folder:
and by running the command "ifconfig", I see my IP address is "192.168.1.222".
A colleague wants to copy project "arrow2" from my computer. Instead of copying the project using USB flash disks and running around the office, I can use the powerful git-daemon command supported by git. Here's how:
1. Assuming the above directory structure, navigate to the "git" folder in the terminal.
2. Type the following command:
- git daemon --base-path=. --export-all
A brief explanation: first we go to the parent folder of "arrow2" (i.e. "git"), then we identify the parameter "--base-path" to be "." (i.e. the current folder), and let git export all projects under current folders.
3. On the receiving computer, launch the terminal, navigate to any directory
4. Type the following command:
- git clone git://192.168.1.222/arrow2 my-arrow2
Here we're using the "git" protocol to transfer files and "192.168.1.222" as the IP address of the computer that you want to copy the project ("arrow2" ) from. The last parameter is "my-arrow2", meaning the new name for the project after you copied.
Bang! We're done. By leveraging git built-in support, transferring any git-supported projects is super fast!
Case 2: The project or folder is not under git control (aka "using SCP")
This is a more likely scenario, so using the SCP command can be pretty handy. For example, in the previous case, you can use the following command on the destination computer:
- scp -r email@example.com:~/xxx/git/arrow2 .
This should be pretty self-explanatory. "tuo" is the user name for your computer, followed by the IP address and the path to source directory. The second argument is to identify the path you want to save to on the destination computer.
Normally, I prefer the first method : git-daemon. It is an anonymous copy, meaning that you don't need to type the user name of source computer, and you can use it on a Windows machine. I always make it a habit to keep files under git control, because it is what git (i.e. git is way beyond just a SCM tool, internally it is file management system) is good at.
You can still use the SCP method on a Windows machine, but it will require a little configuration. When you install git on Windows, there is an option called "git bash". Choose this option and not only can you use SCP on Windows, but you can also use many other UNIX commands from git bash.