Saturday, June 7, 2014

Data Analytics: Introduction to Basic Git

Now that we have learned the importance of data analytics and its applications in our works, businesses and daily lives, we will now discuss the importance of how to store data. Git is a program where your programs can be stored in a remote and local repository. This program is a type of version control system (VCS) and is therefore very helpful if you plan to improve or revise your program more frequently. You can download the Gitbash at this site: http://git-scm.com/downloads.



If you have done installing the Gitbash in your computer, you have to set it up so that you can join the global community of Git users. To set up:
type:

git config --global user.name "your name here"
git config --global user.email "your email here"

to check if the set-up is correct type:

git config --list

to exit the gitbash type:

exit



Now that you have done setting up your Gitbash, let's run down on some basic Git commands:

pwd is the command identifying the current working directory.

clear is the command that cleans the Git console.

ls is the command that lists all the folders and files in the present working directory.

ls-a is the command that presents all the hidden and unhidden files and folders in the current 
working directory.

ls-al is the command that lists all the details in the current working directory.

cd (followed by the name of the directory) is the command that changes one directory to the defined directory.

cd (that is not followed by the name of the directory) is the command that will lead back to the home directory.

cd.. is the command that goes up one level.

cp is the command for copying files.

cp-r is the command for copying a folder and all the files it contained.

rm is the command that remove or delete a file. USE WITH CAUTION THERE IS NO RETRIEVAL OPERATION ONCE DELETED.

rm-r is the command the removes a folder. USE WITH CAUTION THERE IS NO RETRIEVAL OPERATION ONCE DELETED.

mv is the command to move or rename folders.

let's do some simple exercises.
first click the Start menu, then click Computer, Local Disk (C:), click Users and then click User.



Our first exercise to to create a directory named Gerard (or if you want after your first name) at the Computer > Local Disk (C:)> Users>User pathway.
open your Gitbash.
in the Gitbash console type:

mkdir Gerard (I suggest you type your name.)





If you look at the Computer > Local Disk (C:)> Users>User pathway, you can see a new Gerard folder is created. Now let's find out what is the current working directory by typing:

pwd




as you can see the current directory is still at /c/Users/User, this is now yet the working directory that we want, we need to navigate to the Gerard folder . by typing

cd Gerard



Now we are already in the folder Gerard, you can check by looking in the Git console output, it should say: User@User~PC~/Gerard. 

You can also type 

pwd 

to determine what is the current working directory.

after typing pwd you can see that the current working directory is /c/Users/User/Gerard.

We will create new folders under this working directory (the Gerard folder). To create a new directory type:

mkdir Folder 1
mkdir Folder 2
mkdir Note
mkdir Trash



If you have observed in the Gitbash console there is a warning that says mkdir: cannot create directory 'Folder': File exist. this is because on the first syntax command mkdir Folder 1, Gitbash recognizes Folder and 1 as two unique names so it creates two directories one named Folder and the other named 1, when we typed our second syntax command mkdir Folder 2, Gitbash recognizes 2 as a unique name for a directory but it recognizes the word Folder as an existing directory under the current working space.

If you look at your windows and click the Gerard folder, you can see the directories: 1, 2, Folder, Note and Trash.
for the next exercise, we will copy the directory named Folder inside the directory named Note by typing

cp -r Folder Note

in this case, Gitbash recognizes the first directory name as the directory to be copied and the second directory name as the direction where the copied directory will be located.

if you can see the Computer>Local Disk (C:)> Users>User>Gerard>Note pathway has the directory Folder in it.
Now we will try to remove the directory Folder in the Computer>Local Disk (C:)> Users>User>Gerard>Note pathway. First you need to check your current working directory by typing

pwd

if your current working directory is not 

User@User-PC~Gerard/Note

move to the Note directory by typing

cd Note

and try to check your working directory again by typing

pwd

the console should say:

User@User-PC~Gerard/Note

Check the folders in this directory by typing:

ls

(note this is not capital i but a small letter L)

the output should be:

folder

to remove the directory folder in the Note Directory, type

rm-r Folder

As you can see, in the Windows Computer>Local Disk (C:)> Users>User>Gerard>Note pathway, the directory named "Folder" has been deleted. Now we will try to go back to the home directory by typing

cd

check the current working directory by typing

pwd

as you can see the command leads you back to /c/Users/user or  Computer>Local Disk (C:)> Users>User
Now exit the program simply by typing 

exit

You are ready to have your GitHub account to make a remote repository of your programs. Please visit www.github.com to make your account, there is a direction there on how to push your local repository to your remote (online) repository. Just follow the direction on the GitHub and you are ready to go.



No comments:

Post a Comment