Difference between revisions of "Git/C2/Branching-in-Git/English-timed"
From Script | Spoken-Tutorial
PoojaMoolya (Talk | contribs) |
PoojaMoolya (Talk | contribs) |
||
Line 335: | Line 335: | ||
|- | |- | ||
| 09:11 | | 09:11 | ||
− | | Let us summarize. | + | | Let us summarize. In this tutorial, we have learnt about: '''Branching''', Creating a '''branch''' and |
− | |||
− | |||
− | |||
− | |||
− | |||
Switching between the '''master branch '''and the new '''branch''' | Switching between the '''master branch '''and the new '''branch''' | ||
Line 369: | Line 364: | ||
|- | |- | ||
− | |09:52 | + | | 09:52 |
| The Spoken Tutorial Project team conducts workshops and gives certificates to those who pass online tests. | | The Spoken Tutorial Project team conducts workshops and gives certificates to those who pass online tests. | ||
Latest revision as of 10:56, 28 March 2017
|
|
00:01 | Welcome to the spoken tutorial on Branching in Git. |
00:05 | In this tutorial, we will learn about:
Branching Creating a branch and Switching between branches. |
00:15 | For this tutorial, I am using:
Ubuntu Linux 14.04 Git 2.3.2 and gedit Text Editor. |
00:25 | You can use any editor of your choice. |
00:29 | To follow this tutorial, you must have knowledge of running Linux commands on Terminal. |
00:36 | If not, for relevant Linux tutorials, please visit our website. |
00:42 | Let us learn about branching. |
00:44 | Typically, branches are used in a project to develop new modules or to fix a bug. |
00:52 | It helps to work with new modules of a project without disturbing the main project. |
00:58 | The default branch of the Git is master. |
01:02 | We use different branches to develop new modules |
01:06 | and it would be merged with the master branch later. |
01:11 | For example, this diagram visualizes a repository with master and new-module branches. |
01:18 | There are some commits named C1, C2 and C3 in the master branch. |
01:25 | Then a branch 'new-module' is created in C3 commit. |
01:30 | C4, C5 and C8 are the commits of new-module branch. |
01:36 | At the same time, the commits C6 and C7 have been made in the master branch. |
01:43 | Here, you can see that new-module branch is not disturbing the master branch. |
01:49 | Once the new-module is ready, we will merge it back with the master branch. |
01:55 | In this tutorial, I will demonstrate how branch works. Merging will be covered in the next tutorial. |
02:03 | Press Ctrl+Alt+T to open the terminal. |
02:07 | We will open our Git repository mywebpage which we created earlier. |
02:13 | Type: cd space mywebpage and press Enter. |
02:19 | I will continue to use html files for demonstration. You may use any file type of your choice. |
02:28 | Let us check the Git log by typing git space log space hyphen hyphen oneline and press Enter. |
02:37 | First, we will check whether we have any branch in the repository. |
02:43 | Type: git space branch and press Enter. |
02:48 | It shows the default branch 'master', as mentioned earlier. |
02:53 | Now say, I want to create a branch named "new-chapter". |
02:57 | Type: git space branch space new-chapter and press Enter. |
03:04 | Let us see the branch list by typing git space branch and press Enter. |
03:12 | Here, we can see the branch "new-chapter" in the list. |
03:16 | We can also see an asterisk symbol with the master branch. |
03:20 | It indicates that currently we are working in the master branch. |
03:25 | To go into the "new-chapter" branch, type: git space checkout space new-chapter and press Enter. |
03:36 | To check the branch name, type: git space branch and press Enter. |
03:42 | By seeing the asterisk, we can understand that now we are in the "new-chapter" branch. |
03:49 | Next, I will create a html file story.html and commit it for demonstration purpose. |
03:57 | Type: gedit space story.html space ampersand and press Enter. |
04:05 | I will copy and paste some code into this file, from my Writer document, which I had saved earlier. |
04:12 | Save and close the file. |
04:15 | Remember, we have to commit our work whenever we add or remove any file. |
04:21 | To add the file to the staging area, type: git space add space story.html and press Enter. |
04:31 | To commit our work, type: git space commit space hyphen m space within double quotes “Added story.html in new-chapter branch” and press Enter. |
04:47 | Let’s check the Git log of "new-chapter" branch by typing git space log space hyphen hyphen oneline and press Enter. |
04:57 | Here, we can see our latest commit “Added story.html in new-chapter branch”. |
05:04 | Now, let’s say, we want to go back to our master branch to do some work. |
05:10 | So, we’ll type: git space checkout space master and press Enter. |
05:18 | To check the Git log, type: git space log space hyphen hyphen oneline and press Enter. |
05:27 | Here, we can't see the commit “Added story.html in new-chapter branch”. |
05:34 | This is because, that commit belongs to "new-chapter" branch only. |
05:39 | Let’s check the folder content by typing ls and press Enter. |
05:45 | Here, we can't see the file story.html also. |
05:49 | Next, we shall make some changes in the file history.html. |
05:55 | Let's open the file by typing gedit space history.html space ampersand and press Enter. |
06:05 | Let’s add some lines. |
06:08 | Save and close the file. |
06:10 | Let’s commit our work at this point by typing git space commit space hyphen am space within double quotes “Added chapter two in history.html” and press Enter. |
06:26 | Till now, we have been working with the master branch. |
06:30 | Now, let us check if this commit is reflected in new-chapter branch. |
06:36 | To go into new-chapter branch, type: git space checkout space new-chapter and press Enter. |
06:46 | Let’s check the Git log by typing git space log space hyphen hyphen oneline and press Enter. |
06:55 | Here, we can't see the commit “Added chapter two in history.html” as that is in the master branch. |
07:04 | Let’s add some lines in our file story.html. Type: gedit space story.html space ampersand and press Enter. |
07:16 | I will add some lines from my Writer document. |
07:20 | Save and close the file. |
07:22 | To check the Git status, type: git space status and press Enter. |
07:29 | Note that we have not committed our work at this stage. |
07:33 | What do you think will happen if we try to switch branch without committing? This should lead to an error. |
07:41 | Let us try to go back to the master branch. Type: git space checkout space master and press Enter. |
07:51 | This error shows that we can't switch back to other branches without committing the changes. |
07:59 | But, what if I don't want to commit the changes, as they are not important at this stage? This can be done using stashing. |
08:08 | We will learn about stashing in the upcoming tutorials. |
08:13 | For now, we will forcefully exit this branch by using the hyphen hyphen force flag. |
08:19 | Type: git space checkout space hyphen hyphen force space master and press Enter. |
08:28 | Once again, we will go back to new-chapter branch, to check whether the changes are discarded or not. |
08:36 | Type: git space checkout space new-chapter and press Enter. |
08:42 | Let’s open the file story.html by typing gedit space story.html space ampersand and press Enter. |
08:54 | Here we can see that our changes have been discarded.Let us close the gedit. |
09:01 | In the next tutorial, we will learn to merge this new-chapter branch with the master branch. |
09:07 | With this, we come to the end of this tutorial. |
09:11 | Let us summarize. In this tutorial, we have learnt about: Branching, Creating a branch and
Switching between the master branch and the new branch |
09:23 | As an assignment- Create a branch named "chapter-two". |
09:28 | Go into the chapter-two branch. |
09:31 | Do some commits. |
09:33 | Switch back to the master branch. |
09:36 | Check the Git log and understand that, in the master branch, you can't see the commits of the "branch chapter-two". |
09:44 | The video at the following link summarizes the Spoken Tutorial project. Please download and watch it. |
09:52 | The Spoken Tutorial Project team conducts workshops and gives certificates to those who pass online tests. |
09:59 | For more details, please write to us. |
10:03 | Spoken Tutorial Project is funded by NMEICT, MHRD, Government of India. More information on this mission is available at the following link. |
10:15 | This is Priya from IIT Bombay. Thanks for joining. |