Git/C2/Branching-in-Git/English
Title of script: Branching in Git
Author: Priya K
Keywords: Video tutorial, branching, master branch, creating branch, * master, switch branches, --force
|
|
Slide 1:
Branching in Git |
Welcome to the spoken tutorial on Branching in Git. |
Slide 2:Learning Objectives
|
In this tutorial, we will learn about
|
Slide 3:
System requirement
|
For this tutorial, I am using
You can use any editor of your choice. |
Slide 4:
Pre-requisites
|
To follow this tutorial
|
Let us learn about branching. | |
Slide 5a:
Branching
|
* Typically, branches are used in a project to develop new modules or to fix a bug.
|
Slide 5b:
Branching
|
* The default branch of the Git is master.
|
Slide 6:
Branching – Flow diagram
|
For example, this diagram visualizes a repository with master and new-module branches.
|
In this tutorial, I will demonstrate how branching works.
| |
Press Ctrl+Alt+T to open the terminal | Press Ctrl+Alt+T to open the terminal. |
We will open our Git repository mywebpage which we created earlier. | |
Type cd mywebpage and press Enter | Type cd space mywebpage
|
I will continue to use html files for demonstration.
| |
Type git log --oneline and press Enter
|
Let us check the Git log by typing
git space log space hyphen hyphen oneline
|
Type git branch and press Enter
|
First, we will check whether we have any branch in the repository.
|
Type git branch new-chapter and press Enter | Now say, I want to create a branch named new-chapter.
|
Type git branch and press Enter
|
Let us see the branch list by typing git space branch and press Enter.
|
Highlight * master | We can also see an asterisk symbol with the master branch.
|
Type git checkout new-chapter and press Enter | To go into the new-chapter branch, type git space checkout space new-chapter
|
Type git branch and press Enter
|
To check the branch name, type git space branch
|
Type gedit story.html & and press Enter | Next, I will create a html file story.html and commit it for demonstration purpose.
|
Copy and paste some code | I will copy and paste some code into this file, from my Writer document, which I had saved earlier. |
Save and close the file | Save and close the file. |
Remember, we have to commit our work whenever we add or remove any file. | |
Type git add story.html and press Enter
|
To add the file to the staging area, type
git space add space story.html
|
Type git commit -m “Added story.html in new-chapter branch” and press Enter | To commit our work, type
git space commit space hyphen m space within double quotes “Added story.html in new-chapter branch”
|
Type git log --oneline and press Enter | Let’s check the Git log of new-chapter branch by typing git space log space hyphen hyphen oneline
|
Highlight “Added story.html in new-chapter branch” | Here we can see our latest commit “Added story.html in new-chapter branch”.
|
Type git checkout master and press Enter | Now, let’s say we want to go back to our master branch to do some work.
|
Type git log --oneline and press Enter | To check the Git log, type git space log space hyphen hyphen oneline
|
Here we can't see the commit “Added story.html in new-chapter branch”.
| |
Type ls and press Enter
|
Let’s check the folder content by typing ls and press Enter.
|
Type gedit history.html & and press Enter | Next, we shall make some changes in the file history.html.
|
Add some lines | Let’s add some lines. |
Save and close the file | Save and close the file. |
Type git commit -am “Added chapter two in history.html” and press Enter
|
Let’s commit our work at this point by typing
|
Type git checkout new-chapter and press Enter
|
Now, let us check if this commit is reflected in new-chapter branch.
git space checkout space new-chapter
|
Type git log --oneline and press Enter | Let’s check the Git log by typing git space log space hyphen hyphen oneline
|
Here, we can't see the commit “Added chapter two in history.html” as that is in the master branch. | |
Type gedit story.html & and press Enter | Let’s add some lines in our file story.html.
|
Copy and paste the lines | I will add some lines from my Writer document. |
Save and close the file | Save and close the file. |
Type git status and press Enter | To check the Git status, type git space status and press Enter. |
Note that we have not committed our work at this stage.
| |
Type git checkout master and press Enter | Let us try to go back to the master branch.
|
Highlight the error
“Please, commit your changes or stash them” |
This error shows that we can't switch back to other branches without committing the changes. |
But what, if I don't want to commit the changes, as they are not important at this stage?
| |
Highlight stash | We will learn about stashing in the upcoming tutorials. |
Type git checkout --force master and press Enter
|
For now, we will forcefully exit this branch by using the hyphen hyphen force flag.
|
Once again, we will go back to new-chapter branch, to check whether the changes are discarded or not. | |
Type git checkout new-chapter and press Enter | Type git space checkout space new-chapter
|
Type gedit story.html & and press Enter | Let’s open the file story.html by typing gedit space story.html space ampersand
|
Here we can see that our changes have been discarded.
| |
In the next tutorial, we will learn to merge this new-chapter branch with the master branch.
| |
With this, we come to the end of this tutorial. | |
Slide 7:
Summary
|
Let us summarize.
|
Slide 8:
Assignment
|
As an assignment
|
Slide 9:
Acknowledgement
|
The video at the following link summarises the Spoken Tutorial project.
|
Slide 10:
Spoken Tutorial Workshops
|
The Spoken Tutorial Project Team conducts workshops and gives certificates to those who pass online tests.
|
Slide 11:
Acknowledgement
|
Spoken Tutorial Project is funded by NMEICT, MHRD, Government of India.
|
This is Priya from IIT Bombay. Thanks for joining. |