Difference between revisions of "Git/C2/Basic-commands-of-Git/English"
(Created page with "'''Title of script:''' '''Basic commands of Git''' '''Author:''' Priya K '''Keywords:''' '''Video tutorial, Git repository, basic commands, staging area, SHA-1 hash''' {|...") |
Nancyvarkey (Talk | contribs) |
||
Line 24: | Line 24: | ||
| style="border:1pt solid #000000;padding:0.097cm;"| In this tutorial, we will learn about | | style="border:1pt solid #000000;padding:0.097cm;"| In this tutorial, we will learn about | ||
− | |||
* '''Git repository''' and | * '''Git repository''' and | ||
* Some basic commands of '''Git'''. | * Some basic commands of '''Git'''. | ||
− | |||
− | |||
|- | |- | ||
Line 37: | Line 34: | ||
| style="border:1pt solid #000000;padding:0.097cm;"| For this tutorial, I am using | | style="border:1pt solid #000000;padding:0.097cm;"| For this tutorial, I am using | ||
− | |||
* '''Ubuntu Linux 14.04''' | * '''Ubuntu Linux 14.04''' | ||
Line 51: | Line 47: | ||
| style="border:1pt solid #000000;padding:0.097cm;"| To follow this tutorial | | style="border:1pt solid #000000;padding:0.097cm;"| To follow this tutorial | ||
− | |||
* You must have knowledge of running '''Linux '''commands on the '''Terminal.''' | * You must have knowledge of running '''Linux '''commands on the '''Terminal.''' | ||
* If not, for relevant '''Linux '''<nowiki>tutorials, please visit our website. <<PAUSE>></nowiki> | * If not, for relevant '''Linux '''<nowiki>tutorials, please visit our website. <<PAUSE>></nowiki> | ||
− | |||
− | |||
|- | |- | ||
Line 65: | Line 58: | ||
| style="border:1pt solid #000000;padding:0.097cm;"| Now we will see what is '''Git repository.''' | | style="border:1pt solid #000000;padding:0.097cm;"| Now we will see what is '''Git repository.''' | ||
− | |||
* '''Git repository '''is a folder where all the data of our project will be stored. | * '''Git repository '''is a folder where all the data of our project will be stored. | ||
Line 72: | Line 64: | ||
** Normal folder contains only files and directories. | ** Normal folder contains only files and directories. | ||
** But the '''Git repository '''contains set of files and directories, along with their complete history. | ** But the '''Git repository '''contains set of files and directories, along with their complete history. | ||
− | |||
− | |||
|- | |- | ||
Line 92: | Line 82: | ||
You can create the directory wherever you want on your machine. | You can create the directory wherever you want on your machine. | ||
+ | |- | ||
+ | | style="border:1pt solid #000000;padding:0.097cm;"| | ||
− | By default, we are in our '''Home '''directory. | + | | style="border:1pt solid #000000;padding:0.097cm;"| By default, we are in our '''Home '''directory. |
− | Type, | + | Type, |
'''mkdir space mywebpage''' and press''' Enter'''. | '''mkdir space mywebpage''' and press''' Enter'''. | ||
Line 104: | Line 96: | ||
|- | |- | ||
− | | style="border:1pt solid #000000;padding:0.097cm;"| Type''' cd mywebpage''' | + | | style="border:1pt solid #000000;padding:0.097cm;"| Type''' cd mywebpage''' >> press''' Enter'''. |
− | | style="border:1pt solid #000000;padding:0.097cm;"| To go | + | | style="border:1pt solid #000000;padding:0.097cm;"| To go into this '''directory''', type, |
'''cd space mywebpage''' and press''' Enter'''. | '''cd space mywebpage''' and press''' Enter'''. | ||
|- | |- | ||
− | | style="border:1pt solid #000000;padding:0.097cm;"| Type | + | | style="border:1pt solid #000000;padding:0.097cm;"| Type''' git init''' >> press''' Enter''' |
| style="border:1pt solid #000000;padding:0.097cm;"| To make '''mywebpage''' '''directory '''as the '''Git repository''', type''''' ''git space init''' and press''' Enter'''. | | style="border:1pt solid #000000;padding:0.097cm;"| To make '''mywebpage''' '''directory '''as the '''Git repository''', type''''' ''git space init''' and press''' Enter'''. | ||
Line 133: | Line 125: | ||
|- | |- | ||
| style="border:1pt solid #000000;padding:0.097cm;"| Type''''' ''ls -a''' and press''' Enter''' | | style="border:1pt solid #000000;padding:0.097cm;"| Type''''' ''ls -a''' and press''' Enter''' | ||
− | | style="border:1pt solid #000000;padding:0.097cm;"| To see the hidden folder, type | + | | style="border:1pt solid #000000;padding:0.097cm;"| To see the hidden folder, type |
'''ls space hyphen a''' and press''' Enter'''. | '''ls space hyphen a''' and press''' Enter'''. | ||
Line 139: | Line 131: | ||
|- | |- | ||
| style="border:1pt solid #000000;padding:0.097cm;"| Highlight the hidden files | | style="border:1pt solid #000000;padding:0.097cm;"| Highlight the hidden files | ||
− | | style="border:1pt solid #000000;padding:0.097cm;"| It shows the '''dot git '''folder | + | | style="border:1pt solid #000000;padding:0.097cm;"| It shows the '''dot git '''folder. |
Line 163: | Line 155: | ||
|- | |- | ||
− | | style="border:1pt solid #000000;padding:0.097cm;"| <nowiki> | + | | style="border:1pt solid #000000;padding:0.097cm;"| Highlight '''<nowiki>priya.spoken@gmail.com</nowiki>''' |
− | | style="border:1pt solid #000000;padding:0.097cm;"| | + | |
+ | | style="border:1pt solid #000000;padding:0.097cm;"| Here I have used '''<nowiki>priya[dot]spoken[at]gmail[dot]com</nowiki>''' | ||
Line 216: | Line 209: | ||
− | | style="border:1pt solid #000000;padding:0.097cm;"| * Multiple repositories can be created in a single machine. | + | | style="border:1pt solid #000000;padding:0.097cm;"| |
+ | * 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. | * 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. | * 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. | * If you want the identity only for a particular repository, then do not use '''hyphen hyphen global''' flag. | ||
− | |||
− | |||
|- | |- | ||
Line 236: | Line 230: | ||
|- | |- | ||
| style="border:1pt solid #000000;padding:0.097cm;"| Type '''git config --list''' and press '''Enter''' | | style="border:1pt solid #000000;padding:0.097cm;"| Type '''git config --list''' and press '''Enter''' | ||
− | |||
− | |||
| style="border:1pt solid #000000;padding:0.097cm;"| Type '''git space config space hyphen hyphen list''' and press '''Enter.''' | | style="border:1pt solid #000000;padding:0.097cm;"| Type '''git space config space hyphen hyphen list''' and press '''Enter.''' | ||
Line 243: | Line 235: | ||
|- | |- | ||
| style="border:1pt solid #000000;padding:0.097cm;"| Highlight name, email address and editor | | style="border:1pt solid #000000;padding:0.097cm;"| Highlight name, email address and editor | ||
− | | style="border:1pt solid #000000;padding:0.097cm;"| Now, you can see the editor name, email address and username. | + | | style="border:1pt solid #000000;padding:0.097cm;"| Now, you can see the '''editor name, email address''' and username. |
Line 268: | Line 260: | ||
Type''''' ''gedit mypage.html''' '''& '''and press''' Enter''' | Type''''' ''gedit mypage.html''' '''& '''and press''' Enter''' | ||
− | | style="border:1pt solid #000000;padding:0.097cm;"| Switch back to the '''terminal.''' Let me clear the prompt. | + | | style="border:1pt solid #000000;padding:0.097cm;"| Switch back to the '''terminal.''' Let me clear the '''prompt'''. |
− | Now type | + | Now type |
− | '''gedit space mypage.html space ampersand | + | '''gedit space mypage.html space ampersand'''. |
Line 279: | Line 271: | ||
− | We use the & (ampersand) to free up the prompt. | + | We use the '''& (ampersand)''' to free up the '''prompt'''. |
Line 310: | Line 302: | ||
|- | |- | ||
| style="border:1pt solid #000000;padding:0.097cm;"| Switch back to the '''terminal >> '''Type''''' ''git add mypage.html''' and press''' Enter''' | | style="border:1pt solid #000000;padding:0.097cm;"| Switch back to the '''terminal >> '''Type''''' ''git add mypage.html''' and press''' Enter''' | ||
− | | style="border:1pt solid #000000;padding:0.097cm;"| Switch back to the '''terminal''' and type | + | | style="border:1pt solid #000000;padding:0.097cm;"| Switch back to the '''terminal''' and type |
'''git space add space mypage.html''' and press '''Enter'''. | '''git space add space mypage.html''' and press '''Enter'''. | ||
|- | |- | ||
− | | style="border:1pt solid #000000;padding:0.097cm;"| Type | + | | style="border:1pt solid #000000;padding:0.097cm;"| Type''' git status''' >> press''' Enter''' |
| style="border:1pt solid #000000;padding:0.097cm;"| Now we will check the current status of '''Git'''. | | style="border:1pt solid #000000;padding:0.097cm;"| Now we will check the current status of '''Git'''. | ||
− | So type | + | So type '''git space status''' and press''' Enter'''. |
|- | |- | ||
Line 350: | Line 342: | ||
− | Type | + | Type '''git status''' >> press''' Enter''' |
Line 375: | Line 367: | ||
| style="border:1pt solid #000000;padding:0.097cm;"| Slide 8: | | style="border:1pt solid #000000;padding:0.097cm;"| Slide 8: | ||
| style="border:1pt solid #000000;padding:0.097cm;"| Let us switch back to our slides to know more about '''Staging area'''. | | style="border:1pt solid #000000;padding:0.097cm;"| 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. | * '''Staging area''' is a file that stores information of the changes that need to be committed. | ||
Line 381: | Line 372: | ||
* We will discuss more about '''commit''' in the upcoming tutorials. | * We will discuss more about '''commit''' in the upcoming tutorials. | ||
* Older '''Git '''versions used the term''' index''' instead of''' staging area.''' | * Older '''Git '''versions used the term''' index''' instead of''' staging area.''' | ||
− | |||
− | |||
|- | |- | ||
Line 388: | Line 377: | ||
− | Type | + | Type '''git add mypage.html''' >> press''' Enter''' |
| style="border:1pt solid #000000;padding:0.097cm;"| Now, let us see how to add the new changes of the file, to the''' staging area'''. | | style="border:1pt solid #000000;padding:0.097cm;"| 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. | + | Switch back to the''' terminal'''. Let me clear the '''prompt'''. |
Line 398: | Line 387: | ||
|- | |- | ||
− | | style="border:1pt solid #000000;padding:0.097cm;"| Type | + | | style="border:1pt solid #000000;padding:0.097cm;"| Type '''git status''' >> press''' Enter''' |
| style="border:1pt solid #000000;padding:0.097cm;"| To check the '''Git '''status, type''' git space status''' and press''' Enter'''. | | style="border:1pt solid #000000;padding:0.097cm;"| To check the '''Git '''status, type''' git space status''' and press''' Enter'''. | ||
Line 420: | Line 409: | ||
− | | style="border:1pt solid #000000;padding:0.097cm;"| * When we attain a particular stage in our work, we can save them in the '''repository'''. | + | | style="border:1pt solid #000000;padding:0.097cm;"| |
+ | * When we attain a particular stage in our work, we can save them in the '''repository'''. | ||
* This is called '''commit'''. | * This is called '''commit'''. | ||
− | * Each commit is saved with the information of username, email-id, date, time and commit message. | + | * Each '''commit''' is saved with the information of '''username, email-id, date, time''' and '''commit message'''. |
− | + | ||
− | + | ||
|- | |- | ||
Line 430: | Line 418: | ||
− | + | Switch back to the terminal and type '''git commit''' >> press '''Enter''' | |
| style="border:1pt solid #000000;padding:0.097cm;"| Now let us see how to '''commit'''. | | style="border:1pt solid #000000;padding:0.097cm;"| Now let us see how to '''commit'''. | ||
Line 445: | Line 433: | ||
− | | style="border:1pt solid #000000;padding:0.097cm;"| In the first line, I will type “'''Initial commit'''” as the commit message. | + | | style="border:1pt solid #000000;padding:0.097cm;"| In the first line, I will type “'''Initial commit'''” as the '''commit message'''. |
Line 458: | Line 446: | ||
|- | |- | ||
| style="border:1pt solid #000000;padding:0.097cm;"| Highlight Initial commit | | style="border:1pt solid #000000;padding:0.097cm;"| Highlight Initial commit | ||
− | | style="border:1pt solid #000000;padding:0.097cm;"| In future, with this '''commit''' | + | | style="border:1pt solid #000000;padding:0.097cm;"| In future, with this '''commit message''', we can identify what we did till this stage. |
|- | |- | ||
Line 471: | Line 459: | ||
| style="border:1pt solid #000000;padding:0.097cm;"| You will see some details, such as | | style="border:1pt solid #000000;padding:0.097cm;"| You will see some details, such as | ||
− | * The commit message | + | * The '''commit message''' |
* How many files we have changed | * How many files we have changed | ||
* How many insertions we have done and | * How many insertions we have done and | ||
* Name of the file. | * Name of the file. | ||
− | |||
− | |||
|- | |- | ||
Line 483: | Line 469: | ||
|- | |- | ||
− | | style="border:1pt solid #000000;padding:0.097cm;"| Type | + | | style="border:1pt solid #000000;padding:0.097cm;"| Type '''git log''' >> press '''Enter''' |
| style="border:1pt solid #000000;padding:0.097cm;"| Type''' git space log''' and press '''Enter.''' | | style="border:1pt solid #000000;padding:0.097cm;"| Type''' git space log''' and press '''Enter.''' | ||
Line 507: | Line 493: | ||
− | | style="border:1pt solid #000000;padding:0.097cm;"| * '''SHA-1 hash '''is a unique id of 40 alpha-numeric characters. | + | | style="border:1pt solid #000000;padding:0.097cm;"| |
+ | * '''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 '''stores all the informations in its database by the '''hash value.''' | ||
* '''Git '''commits are identified by the '''SHA-1 hash''' | * '''Git '''commits are identified by the '''SHA-1 hash''' | ||
* You will understand the importance of the '''SHA-1 hash '''in future tutorials | * You will understand the importance of the '''SHA-1 hash '''in future tutorials | ||
− | |||
− | |||
|- | |- | ||
Line 526: | Line 511: | ||
− | It shows the details of the '''commit''' such as author name, email address, date, time and the '''commit''' | + | It shows the details of the '''commit''' such as '''author name, email address, date, time''' and the '''commit message''', which we gave earlier. |
Line 541: | Line 526: | ||
| style="border:1pt solid #000000;padding:0.097cm;"| Let us summarize. | | style="border:1pt solid #000000;padding:0.097cm;"| Let us summarize. | ||
− | |||
In this tutorial we have learnt about | In this tutorial we have learnt about | ||
− | * Git repository and | + | * '''Git repository''' and |
− | * Some basic commands of | + | * Some basic commands of '''Git''' like '''git init, status, commit '''and''' log'''. |
− | + | ||
− | + | ||
|- | |- | ||
Line 559: | Line 541: | ||
* Create a '''directory''' in your machine and make it as a '''repository'''. | * Create a '''directory''' in your machine and make it as a '''repository'''. | ||
* Create a text file and add some content into it. | * Create a text file and add some content into it. | ||
− | |||
* Add the file to the '''staging area '''of the '''Git repository.''' | * Add the file to the '''staging area '''of the '''Git repository.''' | ||
* '''Commit''' the file to your '''repository''' and | * '''Commit''' the file to your '''repository''' and | ||
* See the '''commit''' details using '''git log''' command. | * See the '''commit''' details using '''git log''' command. | ||
− | |||
− | |||
|- | |- | ||
Line 576: | Line 555: | ||
Pls download and watch it. | Pls download and watch it. | ||
− | |||
− | |||
− | |||
|- | |- | ||
Line 593: | Line 569: | ||
For more details, please write to us. | For more details, please write to us. | ||
− | |||
− | |||
− | |||
|- | |- | ||
Line 607: | Line 580: | ||
More information on this Mission is available at the following link. | More information on this Mission is available at the following link. | ||
− | |||
− | |||
− | |||
|- | |- |
Latest revision as of 06:58, 30 May 2015
Title of script: Basic commands of Git
Author: Priya K
Keywords: Video tutorial, Git repository, basic commands, staging area, SHA-1 hash
|
|
Slide 1:
|
Welcome to the spoken tutorial on Basic commands of Git. |
Slide 2:
|
In this tutorial, we will learn about
|
Slide 3:
|
For this tutorial, I am using
You can use any editor of your choice. |
Slide 4:
|
To follow this tutorial
|
Slide 5:
|
Now we will see what is Git repository.
|
Press Ctrl+Alt+T to open terminal | Now let us learn to create a Git repository in our local machine.
|
Type mkdir mywebpage and press Enter
|
On my machine, I will create a directory for the Git repository, in my Home directory.
|
By default, we are in our Home directory.
mkdir space mywebpage and press Enter.
| |
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”.
|
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.
|
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
|
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.
|
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.
|
Highlight --global flag
|
Here global flag is optional.
|
Slide 6:
|
|
Switch back to our terminal
|
Switch back to the terminal.
|
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.
|
Slide 7:
|
I will be using html files for demonstration.
For eg: text files or doc files. |
Switch back to the terminal
|
Switch back to the terminal. Let me clear the prompt.
gedit space mypage.html space ampersand.
|
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.
|
Save the file | Now, I will save my file. |
So, I have an html file with some code in it.
| |
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.
|
Highlight the message “new file: mypage.html” | You can see “new file: mypage.html”.
|
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.
|
Save and close the file | Save and close the file. |
Switch back to the terminal
|
Then switch back to the terminal.
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”.
|
<<PAUSE>> | |
Slide 8: | Let us switch back to our slides to know more about Staging area.
|
Switch back to the terminal
|
Now, let us see how to add the new changes of the file, to the staging area.
|
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:”
|
Now we will freeze our code at this point. | |
Slide 9:
|
|
|
Now let us see how to commit.
|
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.
|
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
|
Now let us see the commit details using git log command. | |
Type git log >> press Enter | Type git space log and press Enter. |
|
We have only one commit in our repository.
|
Slide 10:
|
|
|
Let us come back to our terminal.
|
With this, we come to the end of this tutorial. | |
Slide 11:
|
Let us summarize.
In this tutorial we have learnt about
|
Slide 12:
|
As an assignment
|
Slide 13:
Acknowledgement |
The video at the following link summarises the Spoken Tutorial project.
|
Slide 14:
Acknowledgement
|
The Spoken Tutorial Project Team conducts workshops and gives certificates to those who pass online tests.
|
Slide 15:
Acknowledgement |
Spoken Tutorial Project is funded by NMEICT, MHRD, Government of India.
|
This is Priya from IIT Bombay.
|