Script for copying a folder somewhere using Git Bash

Viewed 397

I want to copy a folder ~/Projects/LocalProject onto my server //VM-Server/ServerProject.

I know that I can use GitBash:

cp -r directory-name-1 directory-name-2

But what I'm curious about is, can I create a script to do that by double clicking that script, or adding it as a command to my GitBash, cause I will need that alot?

--Edit--

Tried nothing, as I don't know how to do that. Yes there are hidden files, I don't want them to be copied. There shouldn't be newer files on the destination. I need to manually run it, I thought that's clear as I mentioned the option to have a executable script / or a terminal command.

1 Answers

Option 1: Batch file

You don't even need git-bash; you can make a batch file in any text editor, name it copy to server.bat, and type in cp C:\Users\<Your username>\Projects\LocalProject \\VM-Server\ServerProject.

You can also make a .sh file for use in bash. The command is the same, just make note that Windows uses \, while bash uses / for directory tree

Option 2: Alias

Open your bash_profile file (it's in your git bash install location). Add a line at the end of the file that says alias copyToServer = 'cp ~/Projects/LocalProject //VM-Server/ServerProject'. Then close git-bash, reopen it and use the command by typing copyToServer as a bash command. (It doesn't need to be named copyToServer)

Related