Git/C2/Basic-commands-of-Git/English

From Script | Spoken-Tutorial
Revision as of 06:58, 30 May 2015 by Nancyvarkey (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Title of script: Basic commands of Git

Author: Priya K

Keywords: Video tutorial, Git repository, basic commands, staging area, SHA-1 hash


Visual cue
Narration
Slide 1:


Welcome to the spoken tutorial on Basic commands of Git.
Slide 2:


In this tutorial, we will learn about
  • Git repository and
  • Some basic commands of Git.
Slide 3:


For this tutorial, I am using
  • Ubuntu Linux 14.04
  • Git 2.3.2. and
  • gedit Text Editor

You can use any editor of your choice.

Slide 4:


To follow this tutorial
  • You must have knowledge of running Linux commands on the Terminal.
  • If not, for relevant Linux tutorials, please visit our website. <<PAUSE>>
Slide 5:


Now we will see what is Git repository.
  • Git repository is a folder where all the data of our project will be stored.
  • It can be located on the local machine or on a remote machine
  • The difference between normal folder and a Git repository is:
    • Normal folder contains only files and directories.
    • But the Git repository contains set of files and directories, along with their complete history.
Press Ctrl+Alt+T to open terminal Now let us learn to create a Git repository in our local machine.


Press Ctrl+Alt+T keys to open the terminal.

Type mkdir mywebpage and press Enter


On my machine, I will create a directory for the Git repository, in my Home directory.


You can create the directory wherever you want on your machine.

By default, we are in our Home directory.


Type,

mkdir space mywebpage and press Enter.


So now, we have created a directory mywebpage in our Home directory.

Type cd mywebpage >> press Enter. To go into this directory, type,

cd space mywebpage and press Enter.

Type git init >> press Enter To make mywebpage directory as the Git repository, type git space init and press Enter.
Highlight the message “Initialized empty Git repository


You can see the message “Initialized empty Git repository”.


This indicates that Git is initialized successfully.

Highlight the path And this is the path where Git repository is created in our system.
After initialization, a hidden folder dot git will be created inside the mywebpage folder.
Type ls -a and press Enter To see the hidden folder, type

ls space hyphen a and press Enter.

Highlight the hidden files It shows the dot git folder.


Deleting this dot git folder will delete the whole repository.


So you should be very careful with this dot git folder.

Now we have to set our identity to Git.
Type git config --global user.email priya.spoken@gmail.com and press Enter


To set the email address, type

git space config space hyphen hyphen global space user dot email space priya[dot]spoken@gmail.com

and press Enter

Highlight priya.spoken@gmail.com Here I have used priya[dot]spoken[at]gmail[dot]com


You can use your own valid email address.

Type git config --global user.name spoken and press Enter To set the username, type

git space config space hyphen hyphen global space user dot name space Priya

and press Enter.

Highlight Priya I have used Priya as a username.


Please use your name instead of Priya.

Highlight the name and email address The name and the email address that we set are the identities of the person who is working on Git.
Type git config --global core.editor gedit and press Enter Next I will configure the gedit text editor to give the commit message.


Type git space config space hyphen hyphen global space core dot editor space gedit and press Enter.


Now gedit is configured to Git.

Highlight --global flag


Switch back to our slides


Here global flag is optional.


We will switch back to our slides to know more about global flag.

Slide 6:


  • Multiple repositories can be created in a single machine.
  • If you use hyphen hyphen global flag, the setting will be applied to all the repositories in the machine.
  • So, whenever you create a new Git repository, this setting will be applied, by default.
  • If you want the identity only for a particular repository, then do not use hyphen hyphen global flag.
Switch back to our terminal


Switch back to the terminal.


Now let us check the configuration details of the identity that we set earlier.

Type git config --list and press Enter Type git space config space hyphen hyphen list and press Enter.
Highlight name, email address and editor Now, you can see the editor name, email address and username.


<<PAUSE>>

Slide 7:


I will be using html files for demonstration.


You can use any file type of your choice.

For eg: text files or doc files.

Switch back to the terminal


Clear the prompt


Type gedit mypage.html & and press Enter

Switch back to the terminal. Let me clear the prompt.


Now type

gedit space mypage.html space ampersand.


If you are using another file, then give that filename instead of mypage.html.


We use the & (ampersand) to free up the prompt.


Now press Enter.

Copy and paste the code into the file


I will copy and paste some code into this file, from my Writer document, which I had saved earlier.


Likewise, add some content into your file.

Save the file Now, I will save my file.
So, I have an html file with some code in it.


Note: wherever I use mypage.html, you will have to replace it with your filename.


Next, we will ask Git to follow the file mypage.html

Switch back to the terminal >> Type git add mypage.html and press Enter Switch back to the terminal and type

git space add space mypage.html and press Enter.

Type git status >> press Enter Now we will check the current status of Git.


So type git space status and press Enter.

Highlight the message “new file: mypage.html You can see “new file: mypage.html”.


This means that Git has started following the changes made to this file mypage.html.


This is called “tracking”.

Come to mypage.html file Let us switch back to our file mypage.html.
Add few lines And add a few more lines of code to this file.


Like before, I will copy-paste from my Writer file.

Save and close the file Save and close the file.
Switch back to the terminal


Type git status >> press Enter


Then switch back to the terminal.


As before, to check the current status of Git, type

git space status and press Enter.

Highlight the message “Changes not staged for commit” and “modified: mypage.html It shows “Changes not staged for commit” and “modified: mypage.html”.


This means that the changes we made, have not been added to the staging area.

<<PAUSE>>
Slide 8: Let us switch back to our slides to know more about Staging area.
  • Staging area is a file that stores information of the changes that need to be committed.
  • The file contents should be added to the staging area before committing them.
  • We will discuss more about commit in the upcoming tutorials.
  • Older Git versions used the term index instead of staging area.
Switch back to the terminal


Type git add mypage.html >> press Enter

Now, let us see how to add the new changes of the file, to the staging area.


Switch back to the terminal. Let me clear the prompt.


Type git space add space mypage dot html and press Enter.

Type git status >> press Enter To check the Git status, type git space status and press Enter.
Highlight the message “Changes to be committed: Now you can see the message “Changes to be committed:


This means that the file has been added to the staging area and is ready to be committed.


<<PAUSE>>

Now we will freeze our code at this point.
Slide 9:


  • When we attain a particular stage in our work, we can save them in the repository.
  • This is called commit.
  • Each commit is saved with the information of username, email-id, date, time and commit message.


Switch back to the terminal and type git commit >> press Enter

Now let us see how to commit.


Switch back to the terminal and type git space commit and press Enter.

gedit text editor opens up automatically to get the commit message.
Type Initial commit


In the first line, I will type “Initial commit” as the commit message.


You can type any informative message that you want.


Here you can see some lines begin with hash. You can leave them as it is or you can delete them.


Please write the commit message before or after the hash line.

Highlight Initial commit In future, with this commit message, we can identify what we did till this stage.
Save and close the gedit Let me save and close the editor.
Highlight Initial Commit , 1 file changed, 11 insertions(+), and mypage.html


You will see some details, such as
  • The commit message
  • How many files we have changed
  • How many insertions we have done and
  • Name of the file.
Now let us see the commit details using git log command.
Type git log >> press Enter Type git space log and press Enter.


Highlight SHA-1 hash


We have only one commit in our repository.


It shows a unique ID which is called commit hash or SHA-1 hash.


Switch back to our slides to know more about SHA-1 hash.

Slide 10:


  • SHA-1 hash is a unique id of 40 alpha-numeric characters.
  • Git stores all the informations in its database by the hash value.
  • Git commits are identified by the SHA-1 hash
  • You will understand the importance of the SHA-1 hash in future tutorials


Highlight the name, email address, date and message


Let us come back to our terminal.


It shows the details of the commit such as author name, email address, date, time and the commit message, which we gave earlier.


<<PAUSE>>

With this, we come to the end of this tutorial.
Slide 11:


Let us summarize.

In this tutorial we have learnt about

  • Git repository and
  • Some basic commands of Git like git init, status, commit and log.
Slide 12:


As an assignment
  • Create a directory in your machine and make it as a repository.
  • Create a text file and add some content into it.
  • Add the file to the staging area of the Git repository.
  • Commit the file to your repository and
  • See the commit details using git log command.
Slide 13:

Acknowledgement

The video at the following link summarises the Spoken Tutorial project.


Pls download and watch it.

Slide 14:

Acknowledgement


The Spoken Tutorial Project Team conducts workshops and gives certificates to those who pass online tests.


For more details, please write to us.

Slide 15:

Acknowledgement

Spoken Tutorial Project is funded by NMEICT, MHRD, Government of India.


More information on this Mission is available at the following link.

This is Priya from IIT Bombay.


Thanks for joining.

Contributors and Content Editors

Nancyvarkey, Priyacst